Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 if else in sql

Author  Topic 

jim65
Starting Member

35 Posts

Posted - 2006-02-10 : 16:09:55
I know I can use if(@a=1) do something
can I use (if else) like this way.
if(@a=1 and @b=2) doing something. because I have two conditions
many thanks

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-02-10 : 16:39:15
Yes
read books online

quote:
AND
Combines two Boolean expressions and returns TRUE when both expressions are TRUE. When more than one logical operator is used in a statement, AND operators are evaluated first. You can change the order of evaluation by using parentheses.

Syntax
boolean_expression AND boolean_expression

Go to Top of Page

jim65
Starting Member

35 Posts

Posted - 2006-02-10 : 16:52:52
Thanks, I mean that this should be used in T-SQL.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-10 : 16:55:43
The answer is still yes. Check out SQL Server Books Online for details. It is the help documentation for SQL Server.

Tara Kizer
aka tduggan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-02-11 : 14:29:46
If you gave some better examples it might help, and the strong suggestion about BOL are good, but here are some examples

IF @a = 1 SELECT * FROM sysobjects

IF @a = 1 AND @b = 2 SELECT * FROM sysobjects

IF @a = 1 SELECT * FROM sysobjects
ELSE
SELECT * FROM sysobjects

IF @a = 1 AND @b = 2
BEGIN
SELECT * FROM sysobjects
-- Some other stuff
END
ELSE
IF @a = 1 AND @b = 1
BEGIN
--Stuff
END




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

jim65
Starting Member

35 Posts

Posted - 2006-02-11 : 15:27:06
Thanks a lot. it's huge help.
Go to Top of Page
   

- Advertisement -