现在的位置: 首页 > 综合 > 正文

Using Dynamic SQL Statements in Stored Procedures

2012年10月13日 ⁄ 综合 ⁄ 共 372字 ⁄ 字号 评论关闭
DECLARE @SQL varchar(1000)
SET @SQL = 'SELECT Cus_Name, Cus_City, Cus_Country FROM Customers '
IF @Cus_Name IS NOT NULL OR @Cus_City IS NOT NULL OR _
@Cus_Country IS NOT NULL
SET @SQL = @SQL + 'WHERE '
IF @Cus_Name IS NOT NULL
SET @SQL = @SQL + 'Cus_Name = ' + @Cus_Name
...
EXEC(@SQL)
 
Using Dynamic SQL Statements in Stored Procedures 
http://www.4guysfromrolla.com/webtech/102300-1.shtml
http://www.sqlteam.com/item.asp?ItemID=2077

抱歉!评论已关闭.