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)
 even number

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2006-05-19 : 03:22:55
how can I check if a number is even

in other languages I would do if mynumber Mod 2 Then evennumber
does mod work in sql as well? what's teh syntax?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-19 : 03:24:18
[code]if (@number % 2) = 0
print 'EVEN'
else
print 'ODD'
[/code]


KH

Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2006-05-19 : 03:33:01
thanks..
tell me for if statement do I have to do with a begin or end or can I do it in one like like this:

if @filtered=1 then @valid=0
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-05-19 : 03:52:18
quote:
Originally posted by esthera

thanks..
tell me for if statement do I have to do with a begin or end or can I do it in one like like this:

if @filtered=1 then @valid=0



Yes you can, but it makes no sense. You only need a BEGIN...END if you want to execute several statements for the investigated situation, like:

If This Is True
BEGIN
Do This
Do This Too
Do This Last
END
ELSE
Do Only This

In your case, the code should look like:

if @filtered=1 then SELECT @valid=0
or
if @filtered=1 then SET @valid=0


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-19 : 04:02:30
The word THEN is not needed in SQL (It is front end sysntax)


if @filtered=1
SELECT @valid=0

or

if @filtered=1
SET @valid=0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -