luckyboy Level: VB Lord Registered: 05-05-2005 Posts: 160
can not used if in function
hi all. i wonder why i can not used IF statement in sql function.
Im very sure that in table tblBlock_Room have only roomid=1092. i don know why, my test value never 1. any idea?
---function---
SELECT @roomidT=Count(roomid) from tblBlock_Room WHERE roomid=1092
IF @roomIDT =0
BEGIN
SET @TestValue=1
END
____________________________
Please help out.
27-05-2006 at 10:14 AM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 891
Re: can not used if in function
Hi,
You say that your table does have a roomid of 1092, therefore count would be >=1, therefore your IF will never work.
Regards,
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
27-05-2006 at 07:34 PM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 891
Re: can not used if in function
BTW.
If you don't care how many records are in the table that match you should use the EXISTS keyword as it is much more efficient:
IF EXISTS (SELECT RoomID FROM tblBlock_Room WHERE RoomID=1092)
BEGIN
SET @TestValue=1
END
Hope this helps
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)