borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (DELAY FUNCTION)Next Topic (VB compile error with Access 2003 Form across network) New Topic New Poll Post Reply
AndreaVB Forum : Database : can not used if in function Solved Topic
Poster Message
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon 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)

27-05-2006 at 07:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : can not used if in function Solved Topic
Previous Topic (DELAY FUNCTION)Next Topic (VB compile error with Access 2003 Form across network) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder