首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个简单的有关问题(,解决马上给分)

2012-03-23 
一个简单的问题(在线等,解决马上给分)declare@svarchar(8000)declare@evarchar(8000)declare@iintSelect@e

一个简单的问题(在线等,解决马上给分)
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   ( '+@E+ ')   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 ( '+@E+ ') AND ddbh = 103 '

exec sp_executesql @s,N '@n int out ',@n out

select @n
--Return exec(@S)

热点排行