请教个sql语句

Mark杨 2010-03-26 10:23:15
select SUM(mony) from table1 where part not in ('电修','机修')
这有结果
declare @a nvarchar(200)
select @a = parts from table2
print @a -->'电修','机修'
select SUM(mony) from table1 where part not in (@a)
没结果了
...全文
35 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
黄_瓜 2010-03-26
  • 打赏
  • 举报
回复
declare @a nvarchar(200)
select @a = parts from table2
print @a -->'电修','机修'
exec('select SUM(mony) from table1 where part not in ('''+@a+''')')
东那个升 2010-03-26
  • 打赏
  • 举报
回复
只能UP了
htl258_Tony 2010-03-26
  • 打赏
  • 举报
回复
或者:

declare @a nvarchar(200)
select @a = parts from table2
print @a -->'电修','机修'
EXEC('select SUM(mony) from table1 where part not in ('+@a+')')
黄_瓜 2010-03-26
  • 打赏
  • 举报
回复
declare @a nvarchar(200)
select @a = parts from table2
print @a -->'电修','机修'
exec('select SUM(mony) from table1 where part not in ('+@a+')')
htl258_Tony 2010-03-26
  • 打赏
  • 举报
回复
declare @a nvarchar(200)
select @a = parts from table2
print @a -->'电修','机修'
select SUM(mony) from table1 where charindex(','+part+',',','+@a+',')=0

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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