sql语句判断不为空怎么写

chgjz 2009-11-20 12:00:43
declare @temp int (注意:这个@temp是找不到任何值的)
set @temp=(select * from a where id=1)
if(@temp 这个位置如何判断)
update B set name=ll where .....
...全文
10305 41 打赏 收藏 转发到动态 举报
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
sd722522 2012-08-17
  • 打赏
  • 举报
回复
LZ语句就有问题啊
ZhnToNet 2010-08-18
  • 打赏
  • 举报
回复
楼上很多说得都没错,lZ自己的查询语句又出错了。哈哈哈
walkfish_tao 2010-06-30
  • 打赏
  • 举报
回复
应该这样写:
set @temp=(select ISNull(字段,0) from a where id=1)
if @temp>0
begin

end
zhuyicheng188 2010-04-26
  • 打赏
  • 举报
回复
应该是这样的吧!
if(@temp!=null and @temp!='') 估计应该可以的哦!
推荐个链看看吧!
http://www.sjczk.info/
http://www.mtcoll.cn/
telankes2000 2009-12-05
  • 打赏
  • 举报
回复
if exsits(select * from a where id=1)
update B set name=ll where .....
msy_84 2009-12-05
  • 打赏
  • 举报
回复
set @temp=(select * from a where id=1) 这条语句本身就不对 , 给一个变量赋值是 SELECT * 吗?
判断不为空的 IF(@temp IS NOT NULL)
qq346127416 2009-11-20
  • 打赏
  • 举报
回复
IF @temp IS NOT NULL
ji_ju 2009-11-20
  • 打赏
  • 举报
回复
19咯的顶
我姓区不姓区 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 ojlovecd 的回复:]
int型参数你怎么可能把一个集合赋给它……
错误提示也已经很清楚了
declare @temp int
set @temp=selectcount(1) from a where id=1
if(@temp >0)
update B set name=ll where .....
[/Quote]
把括号给忘了……
set @temp=(selectcount(1) from a where id=1)
白云任去留 2009-11-20
  • 打赏
  • 举报
回复
19楼正解
我姓区不姓区 2009-11-20
  • 打赏
  • 举报
回复
int型参数你怎么可能把一个集合赋给它……
错误提示也已经很清楚了
declare @temp int
set @temp=select count(1) from a where id=1
if(@temp >0)
update B set name=ll where .....
panhaichun 2009-11-20
  • 打赏
  • 举报
回复
其实你的改为一条语句就行了


update B set name=ll where ..... and exists(select * from a where id=1)
wuyq11 2009-11-20
  • 打赏
  • 举报
回复
语法问题使用临时表
或select isnull(字段,0) from Tb
风骑士之怒 2009-11-20
  • 打赏
  • 举报
回复
is not null
dotnet201 2009-11-20
  • 打赏
  • 举报
回复
楼上的不错
tkscascor 2009-11-20
  • 打赏
  • 举报
回复
if(@temp is not null and @temp!=0)
Aarom123 2009-11-20
  • 打赏
  • 举报
回复
is not null
tkscascor 2009-11-20
  • 打赏
  • 举报
回复
.........
set @temp=(select * from a where id=1)
你这里返回多个字段了..... select 字段 from a where id=1

if(@temp !=0)
chgjz 2009-11-20
  • 打赏
  • 举报
回复
试过了 is not null , is null, <>0 都出现了错误
错误如下:子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
可以肯定@temp 是没有值的
mytimes_walker 2009-11-20
  • 打赏
  • 举报
回复
IF @temp IS NOT NULL AND @temp != ''
加载更多回复(18)

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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