紧急 求助!!sql 函数值如何返回

為n1輕描淡 2017-03-02 10:48:53
declare @inv_code NVARCHAR(20)
declare @comp_code NVARCHAR(20)
declare @copy_code NVARCHAR(10) --生成批次码必备条件
set @inv_code='QEXX001000070'
set @comp_code='3235'
set @copy_code='001'
declare @bar_dode_auto nvarchar(100)
declare @equi_card_code nvarchar(100)
--遍历临时表
declare @sql nvarchar(4000)
set @sql=''
DECLARE cu_id CURSOR FOR select equi_card_code from equi_bar_code_own_one
where is_bar_code=1 and comp_code=@comp_code and copy_code=@copy_code
order by order_code asc
OPEN cu_id
fetch next from cu_id into @equi_card_code
WHILE(@@FETCH_STATUS = 0)
begin
--遍历临时表中的数据,和字段进行对比,如果存在就将传入的值,组装成批次吗
set @sql= @sql+' dbo.getspellcode(isnull('+@equi_card_code+' ,'''' ),'''')+'
fetch next from cu_id into @equi_card_code
end
close cu_id
deallocate cu_id
-- print @sql
set @sql=left(@sql,len(@sql)-1)


set @sql=' select @bar_dode_auto='+@sql+' from mate_inv_dict where comp_code='''+@comp_code+''' and copy_code='''+
@copy_code+''' and inv_code='''+@inv_code+''''

-- select @sql
--select @bar_dode_auto
--select @sql
...全文
191 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
為n1輕描淡 2017-03-02
  • 打赏
  • 举报
回复
我 select @sql
下面是语句
select @bar_dode_auto= dbo.getspellcode(isnull(inv_code ,'' ),'') from mate_inv_dict where comp_code='3235' and copy_code='001' and inv_code='QEXX001000070'

我现在想将 @bar_dode_auto 返回出去,写上return @bar_dode_auto 返回null ,求助大神帮助,存储过程老大不让写,必须用函数。
二月十六 2017-03-02
  • 打赏
  • 举报
回复
是这样么?
EXEC(@sql)
xdashewan 2017-03-02
  • 打赏
  • 举报
回复
存储过程?存储过程的话用out返回
為n1輕描淡 2017-03-02
  • 打赏
  • 举报
回复
现在问题是,我动态拼装的sql,查出来的值,我现在返回,返回不了,什么情况

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧