openquery 带参数的方法及exec返回结果到变量中的方法

openquery 带参数的方法及exec返回结果到变量中的方法

declare @QTYRECEIVED int
declare @RECEIPTKEY nvarchar(50)
declare @SKU nvarchar(50)
set @RECEIPTKEY='1209010002'
set @SKU='922W1B32BL080'
declare @Sql nvarchar(1000)
SET @Sql = 'SELECT RECEIPTKEY,SKU,QTYRECEIVED FROM WMWHSE1.RECEIPTDETAIL WHERE RECEIPTKEY='''+@RECEIPTKEY+''' AND SKU='''+@SKU+''''
SET @Sql = 'SELECT @QTYRECEIVED=SUM(QTYRECEIVED) FROM OPENQUERY([INFORWMS], ''' + REPLACE(@Sql, '''', '''''') + ''') GROUP BY RECEIPTKEY,SKU'
exec sp_executesql @Sql,N'@QTYRECEIVED int output',@QTYRECEIVED output
select @QTYRECEIVED

转载请注明出处:

转载自http://lxfamn.cn/blog

未经允许不得转载:lxfamn » openquery 带参数的方法及exec返回结果到变量中的方法

赞 (0) 打赏

置顶推荐

评论 0

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏