一字符串相加的问题,提示必须声明变量!! 帮助看看,急~在线
DECLARE @STRSQL VARCHAR(5000)
DECLARE @DCOUNT INT
SET @STRSQL= 'SELECT @DCOUNT=COUNT(*) FROM XC_ORDERPRODUCTLIST WHERE X_ParentID=3761 AND X_Branch2SucFlag=1 '
EXEC(@STRSQL)
我想给@DCOUNT取值,但是放在字符串里面不能通过
------解决方案--------------------这样不行吗?
DECLARE @DCOUNT INT
SELECT @DCOUNT=COUNT(*) FROM XC_ORDERPRODUCTLIST WHERE X_ParentID=3761 AND X_Branch2SucFlag=1
------解决方案--------------------晕倒
@DCOUNT声明和@DCOUNT附值不在一个作用域
------解决方案--------------------不好意思,修改下
DECLARE @STRSQL NVARCHAR(4000) --改為NVARCHAR
DECLARE @DCOUNT INT
SET @STRSQL= N 'SELECT @DCOUNT=COUNT(*) FROM XC_ORDERPRODUCTLIST WHERE X_ParentID=3761 AND X_Branch2SucFlag=1 '
EXEC sp_executesql @STRSQL, N '@DCOUNT INT Output ', @DCOUNT Output
Select @DCOUNT