这样的sql语句怎么实现!!!

lanfanghelanfanghe 2004-09-22 01:12:17
exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
select io_flag,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2)

如果取出io_flag的值大于6 ,我就把substring(io_flag,1,5)插入目标表里
如果取出io_flag的值小于或等于6 ,我就把io_flag插入目标表里
如何解决,请大家帮忙!!
...全文
71 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanfanghelanfanghe 2004-09-22
  • 打赏
  • 举报
回复
几位老兄,是我错了,呵呵!!!
pbsql 2004-09-22
  • 打赏
  • 举报
回复
我的理解是可能楼主叙述有误^_^
zjcxc 元老 2004-09-22
  • 打赏
  • 举报
回复
一楼看错了吧? "如果取出io_flag的值大于6",不是len

不过,楼主要取 substring(io_flag,1,5) ,似乎又应该是 len 的理解才对
zjcxc 元老 2004-09-22
  • 打赏
  • 举报
回复
declare @表 sysname
exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
select case when io_flag>=6 then substring(io_flag,1,5) else io_flag end,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2')
xlhl 2004-09-22
  • 打赏
  • 举报
回复
exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
select case when io_flag>6 then substring(io_flag,1,5) else io_flag end io_flag,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2)
pbsql 2004-09-22
  • 打赏
  • 举报
回复
exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
select case when len(io_flag)>=6 then substring(io_flag,1,5) else io_flag end,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2')

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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