sql语句哪里出错

来源:百度知道 编辑:UC知道 时间:2024/06/01 11:06:09
if not exists(select count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因'))>10
begin
print '严重警告和处罚!'
end
else
begin
print '轻微警告!'
end

这个if后面的语句,里面的语句select count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因')执行的结果是5,5>10不成立,则执行print '轻微警告!'
现在我这里出现了错误,

出现的错误是:
消息 102,级别 15,状态 1,第 1 行
'>' 附近有语法错误。
消息 156,级别 15,状态 1,第 5 行
关键字 'else' 附近有语法错误。

我的哪里问题呢!我找不到,哪位有时间帮我分析下!

if (select count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因')) >10
begin
print '严重警告和处罚!'
end
else
begin
print '轻微警告!'
end

为什么楼主要用not exists 呢?

not exists要去掉吧。

if not exists(select count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因' having count(*)>10) print '严重警告和处罚!' else print '轻微警告!'

exists 本身就是一个判断了

通过sql语句直接得出记录数是否大于10
select count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因' having count(*)>10

然后用exists 判断结果是否存在。
然后print显示结果

declare @cn integer
select @cn=count(*) from bbsreply where ruid in (select uid from bbsusers where uname='可卡因' )

if @cn>10
.......--继续你的代码