我要在数据库dataA中修改数据库dataB的表table1数据,
存储过程中的语句如下:
declare @cou as int; SELECT @cou=count(*) FROM @DataBase..CurrentStock WHERE [email protected] and [email protected]
IF(@cou> 0)
...
运行时提示 '. '附近有语法错误
[email protected].CurrentStock该怎么表达
[email protected],
[email protected]?的功能,
declare @cou as int;
SET @sSql= 'SELECT @cou=count(*) FROM '[email protected]+ ' ..CurrentStock WHERE cWhCode= ' ' '[email protected]+ ' ' ' and cInvCode= ' ' '[email protected]+ ' ' ' '
exec(@sSql)
IF(@cou> 0)
[email protected]
望哪位大侠可以帮忙解决
急!!!
------解决方案--------------------
declare @cou as int;
SET @sSql = 'SELECT @cou=count(*) FROM '[email protected]+ ' ..CurrentStock WHERE cWhCode= ' ' '[email protected]+ ' ' ' and cInvCode= ' ' '[email protected]+ ' ' ' '
exec sp_executesql @sSql,N '@cou SYSNAME OUT ', @cou OUT
IF(@cou> 0)
------解决方案--------------------
declare @cou as int
declare @sSql nvarchar(100)
SET @sSql= 'SELECT @cou=count(*) FROM '[email protected]+ ' ..CurrentStock WHERE cWhCode= ' ' '[email protected]+ ' ' ' and cInvCode= ' ' '[email protected]+ ' ' ' '
execute sp_executesql @sSql,N '@cou int out ',@cou out [email protected] 一定要是nvarchar类型
print @cou
------解决方案--------------------
LS simonhehe(猩猩无罪) 的办法很好,不过有个地方有笔误
改一改
exec sp_executesql @sSql,N '@cou int OUT ', @cou OUT
------解决方案--------------------
楼主的第一个问题也可以用 simonhehe(猩猩无罪) 的方法解决
第二个问题也可以用 simonhehe(猩猩无罪) 的方法解决
楼主可以看看sql帮助中 sp_executesql的用法
具体如下:
declare @wlbm varchar(20),@CKBH varchar(10) ,@kcsl as real
SET @sSql= 'UPDATE '[email protected]+ ' ..CurrentStock SET iQuantity= [email protected] WHERE [email protected] and [email protected] '
print @sSql
execute sp_executesql @sSql,N '@wlbms varchar(20),@CKBHs varchar(10) ,@kcsls as real ',@[email protected],@[email protected] ,@[email protected]