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)
 simple if statement

Author  Topic 

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2006-10-30 : 03:50:23
hi,
how to use '=' operator in conditional statement

for ex: in C language
if( a==b&&b==c)

how to use same statement in sql server is this wright
if(a=b and b=c)

if so , will a is assaigned by new value provided by b in if statement?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-30 : 03:53:03
I have no idea what
quote:
if so , will a is assaigned by new value provided by b in if statement?
means.

But otherwise

IF a = b AND b = c
-- do something here

IF a = b OR b = c
-- do something here


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-30 : 03:53:49
quote:

how to use same statement in sql server is this wright
if(a=b and b=c)

Yes

quote:
if so , will a is assaigned by new value provided by b in if statement?

No. It is comparision operator


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-30 : 04:00:14
In SQL Server the = sign is both Assignment Operator as well as equal operator.

from Books OnLine
quote:
Assignment Operator
Transact-SQL has one assignment operator, the equals sign (=). In this example, the @MyCounter variable is created. Then, the assignment operator sets @MyCounter to a value returned by an expression.

DECLARE @MyCounter INT
SET @MyCounter = 1



quote:
= (Equals)
Compares two expressions (a comparison operator). When you compare nonnull expressions, the result is TRUE if both operands are equal; otherwise, the result is FALSE. If either or both operands are NULL and SET ANSI_NULLS is set to ON, the result is NULL. If SET ANSI_NULLS is set to OFF, the result is FALSE if one of the operands is NULL, and TRUE if both operands are NULL.

Syntax
expression = expression




KH

Go to Top of Page

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2006-10-30 : 04:39:05
Thank u for ur suggestions
Go to Top of Page

samuelclay
Yak Posting Veteran

71 Posts

Posted - 2006-10-30 : 15:39:05
The = is both an asignment operator and as a comparison operator, but it doesn't do both at the same time.

so saying
IF (@A=@B)
-- Do something

does not assign the value of B to A like some languages do.
Go to Top of Page
   

- Advertisement -