1
我需要從動態SQL達到返回值。我使用sp_executesql作爲字符串執行select查詢。我必須達到結果。這裏是SQL查詢:將動態SQL的字符串值轉換爲SQL Server中的Select查詢
DECLARE @dynsql nvarchar(max)
SET @dynsql = 'select @InvoiceNo=InvoiceNo from '+ QUOTENAME(@DynDB) +'.[dbo].[TableName] where UserID = '+
cast(@UserID as nvarchar)
EXEC sp_executesql @dynsql
問題:這@dynsql是字符串值,我要達到這個SQL查詢的值。