declare @s varchar(8000)
declare @e varchar(8000)
declare @i int
Select @e = ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
Set @s = 'Select Count(*) From ddjgzl Where ddbh in ( '[email protected]+ ') AND ddbh = 103 '
Return exec(@S)
以上语句 我怎么取到 EXEC(@S) 的值
------解决方案--------------------
declare @s varchar(8000)
declare @e varchar(8000)
declare @i int
Select @e = ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
Select @i =Count(*) From ddjgzl Where ddbh in (
Select ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
) AND ddbh = 103
Return @i
------解决方案--------------------
如果是在函数中
declare @s varchar(8000)
declare @e varchar(8000)
declare @i int
Select @i =Count(*) From ddjgzl Where ddbh in (
Select ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
) AND ddbh = 103
Return @i
如果是在存储过程中
declare @s nvarchar(8000)
declare @e nvarchar(8000)
declare @i int
set @e= 'Select @i =Count(*) From ddjgzl Where ddbh in (
Select ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
) AND ddbh = 103 '
exec sp_execute @e,N '@i int output ',@i output
select @i
------解决方案--------------------
--不好意思,没有改数据类型,你现在看一下
declare @s nvarchar(8000)
declare @e nvarchar(8000),@n int
declare @i int
Select @e = ddbh From kjnd , mzmxbjzjg Where kjnd.bh = mzmxbjzjg.kjndbh and kjnd.sybz = 1
Set @s = 'Select @n = Count(*) From ddjgzl Where ddbh in ( '[email protected]+ ') AND ddbh = 103 '
exec sp_executesql @s,N '@n int out ',@n out
select @n
--Return exec(@S)