IF (select count(USERID) from users where UserID = 10)
begin
print 'found ID'
end
If balks and says non-boolean type specified in a context where a condition
is specified, near BEGIN
Thanks,
BUC
IF Exists (select * from users where UserID = 10)
begin
print 'found ID'
end
Tom
<Buc> wrote in message news:eHUl8mE%23GHA...@TK2MSFTNGP05.phx.gbl...
> IF (select count(USERID) from users where UserID = 10)
> begin
> print 'found ID'
> end
>
IF EXISTS(SELECT * FROM users WHERE UserID=10)
I assume this is in an SP.
If all you want to do is test to see if a usedid is in a table
try
if not exists (select * from users where UserID = 10)
begin
do this
end
else
begin
do the other
end
A SELECT statement does not have a data type in SQL.
if exists(Select UserID from users where UserID=10)
begin
print 'found ID'
end
<Buc> wrote in message news:eHUl8mE%23GHA...@TK2MSFTNGP05.phx.gbl...
if not exists (select * from users where userid =10)
begin
do something
end
and the other way to see if it does exist is
if exists (select * from users where userid =10)
begin
do something
end
Immy
<Buc> wrote in message news:eHUl8mE%23GHA...@TK2MSFTNGP05.phx.gbl...
IF (select count(USERID) from users where UserID = 10) > 0
begin
print 'found ID'
end
Using Count(*) instead of Count(UserID) is also faster because it won't
check for the possibility of a null value for UserId; something which is
impossible here because of the Where statement (UserId = 10).
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
<Buc> wrote in message news:eHUl8mE%23GHA...@TK2MSFTNGP05.phx.gbl...