select ? from ? where notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
想写这么一个查询语句。查询 notes和pbjtnote 表中 是否存在 类别、用户、编号相同的列。
select count(nid) from notes,pbjtnotewhere notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
if count(nid)>0 then
……
else ……
end if这样对吗?
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
想写这么一个查询语句。查询 notes和pbjtnote 表中 是否存在 类别、用户、编号相同的列。
select count(nid) from notes,pbjtnotewhere notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
if count(nid)>0 then
……
else ……
end if这样对吗?
我觉得用
select count(*)into :n……
这里怎么能用 JOIN ?
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
if count(nid)>0 then
……
else ……
end if 这样就可以了。大于0就存在
select @i=count(nid)
from notes,pbjtnotewhere notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid
if @i>0
....
else if
.....
else
....
declare @i int
select @i=count(nid)
from notes as a
where exists
(select 1 from pbjtnote as b where a.nid=b.nid and a.typeid=b.typeid and a.userid=b.userid)if @i>0
....
else if
.....
else
....
select count(*)
into :n
from notes,pbjtnotewhere notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid;
然后就是判断n了
当n<>0 是(已表示存在)
update notes
set comn=:ncom
where notes.nid= pbjtnote.nid and
notes.typeid= pbjtnote.typeid and
notes.userid= pbjtnote.userid;但是执行上面更新时报
SQLSTATE = 22005
[Microsofte][odbc sql server driver]对于造型说明无效的字符
notes 表结构是
typeid varchar 20 主
nid int 4 主
userid varchar 20 主
uptime datetime 8 主
comn text 16
if exists (select * from a join b on a.c1=b.c1 and a.c2=b.c2 and .......)
不复杂吧
用 exists 明白了。
但是在程序里没有这么用过。
if exists (select * from a join b on a.c1=b.c1 and a.c2=b.c2 and .......) then
update……//如果存在 就做更新
else
insert……//否则 做插入
end if
这样对吗?
if exists (select * from notes where notes.nid = :nid and notes.typeid =:typeid and notes.userid=:userid) thenupdate……//如果存在 就做更新
else
insert……//否则 做插入
end if 说明一下 nid typeid userid 这三个变量是当前的编号,种类编号,用户
程序报Syntax error 和 Condition for if statement must be a boolean
nid 是int
但是我想写在程序里
你那exists 能用吗?求教了
这是我写好的
select count(*)
into :n
from notes
where notes.nid = :nid and
notes.typeid = :typeid and
notes.userid=:userid ;
messagebox("",n)
你看看能用你的写吗?谢谢了