各位高手,请帮帮忙!!!!!在线等@!谢谢!!!

amwsfcomk 2007-06-18 05:03:29

以下这句话,我该如何写呢????
if not exists(select * from @tabname where material_id=@materialid)

谢谢!!!
...全文
155 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
amwsfcomk 2007-06-19
谢谢!各位!!!

declare @sql varchar(8000)
set @sql='if not exists(select * from '+@tabname+' where material_id='+rtrim(@materialid)
exec(@sql+'
insert into '+@tabname+'(material_id,levelonecode,levelonename,leveltwocode,leveltwoname,levelthreename)
values('''+@materialid+''','''+@onematerialcode+''', '''+@onematerialname+''','''+@twomaterialcode+''', '''+@twomaterialname+''','''+@threematerialname+''')
')

这个是正确答案!!!!
回复
hui_hui_2007 2007-06-18
declare @sql varchar(8000)
set @sql='if not exists(select 1* from '+@tabname+' where material_id='+rtrim(@materialid)
exec(@sql)
回复
tgv_mic 2007-06-18
这是干吗呢? 我咋看都看不懂呢?
回复
gahade 2007-06-18
放在同一个变量里,这样试一下

declare @sql varchar(8000)
set @sql='if not exists(select * from '+@tabname+' where material_id='+rtrim(@materialid)
print(@sql+'
insert into '+@tabname+'(material_id,levelonecode,levelonename,leveltwocode,leveltwoname,levelthreename)
values('''+@materialid+''','''+@onematerialcode+''', '''+@onematerialname+''','''+@twomaterialcode+''', '''+@twomaterialname+''','''+@threematerialname+''')
')
回复
amwsfcomk 2007-06-18
谢谢!!!!好像不行呢!
declare @sql varchar(8000)
set @sql='if not exists(select * from '+@tabname+' where material_id='+rtrim(@materialid)
exec(@sql)
begin
exec('
insert into '+@tabname+'(material_id,levelonecode,levelonename,leveltwocode,leveltwoname,levelthreename)
values('''+@materialid+''','''+@onematerialcode+''', '''+@onematerialname+''','''+@twomaterialcode+''', '''+@twomaterialname+''','''+@threematerialname+''')
')
end

我那句话是在前面起一限制作用的,!!谢谢!1!
回复
hellowork 2007-06-18
if not exists(select * from @tabname where material_id= '''' + @materialid + '''')
回复
gahade 2007-06-18
declare @sql varchar(8000)
set @sql='if not exists(select * from '+@tabname+' where material_id='+rtrim(@materialid)
exec(@sql)
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2007-06-18 05:03
社区公告
暂无公告