SQL:exec sp_executesql usage

--This is an invalid process declare @sql nvarchar(500), @where nvarchar(500),@i nvarchar(64),@p nvarchar(50),@id int set @id=5 set @sql='select '+@p+'=AreaCode from AdministrativeAreaList where AreaID='+cast(@id as varchar) --select @sql exec @sql --Test results: 未能找到存储过程 ''.
---sql server 2000/2005 Tu Juwen 20130716 DECLARE @TableName VARCHAR(500),@sql NVARCHAR(200),@OrderID INT,@c nvarchar(50),@cstucount nvarchar(50) SET @TableName = 'AdministrativeAreaList '; SET @OrderID = 5; SET @sql = 'SELECT top 1 @c=AreaCode FROM AdministrativeAreaList WHERE AreaID ='+cast(@OrderID as nvarchar)+' ORDER BY AreaID DESC' exec sp_executesql @sql,N'@c nvarchar(50) output',@cstucount output--WillexecResults in the variable approach select @cstucount

Posted by Andrea at November 25, 2013 - 9:11 AM