create function getskfse3(@gysdm varchar(30),@syyf smallint) returns float as
begin
declare @result float
declare @i smallint
declare @sqltxt varchar(1500) /*问题出在这里*/
set @sqltxt= 'csye '
if @syyf=1 select @result=isnull(csye,0) from qmye2006 where [email protected]
set @i=1
if @syyf> 1 and @syyf <=12
begin
while @i <[email protected]
begin
if len(@sqltxt)> 0 set @[email protected]+ '+ '
set @[email protected]+ 'zc '+convert(varchar,@i)+ '-sr '+convert(varchar,@i)+ '-xycj '+convert(varchar,@i)
set @[email protected]+1
end
select @result=(@sqltxt) from qmye2006 where [email protected]
end
return @result
end
执行:
select dbo.getskfse3( 'JDBE-000 ',12)
提示:
将数据类型 varchar 转换为 float 时出错。
我在调试的时候,返回 varchar (1500) [email protected]:
csye+sr1-zc1-xycj1+sr2-zc2-xycj2+sr3...
本意是通过select @[email protected]
我理想的结果应该是:
select @result=csye+sr1-zc1-xycj1+sr2-zc2-xycj2+sr3 from qmye2006 where [email protected]
得出结果返回的...现在出错,
应该是在select @[email protected] 这个部分,请教什么原因呢?用什么可以代替让sql执行?
------解决方案--------------------
在exec執行
------解决方案--------------------
好象是这样的 用的 exec( ' ')