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 2005 Forums
 Transact-SQL (2005)
 If Statement to check for field value

Author  Topic 

Guestuser18
Starting Member

34 Posts

Posted - 2009-11-05 : 05:29:55
Hi

I need to write an if statement to check if a field value is between 1-6, i.e. if the number was changed to 1 or 2 or 3 etc

How can I do this?

I need something like

(if value = 1-6) then....

Any help would be great

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 05:36:28
Can you be more specific please?

What do you want to do?
Is it inside an SQL statement?
Example?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Guestuser18
Starting Member

34 Posts

Posted - 2009-11-05 : 05:45:39
I'm writing a trigger.
I need to check if the field that has just been updated has a number between 1-6, so something like.

if (:NEW.value 1-6) then do something

Does make sense?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 05:48:05
Once again.
Please show what you want to do inside the trigger.
This question cannot be answered well without knowing the wanted statement.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Guestuser18
Starting Member

34 Posts

Posted - 2009-11-05 : 05:56:01
No I'm not detailing my whole trigger in this post just to try and get an answer to 1 if statement. Surely what I have provided is enough info. Forget the rest of the trigger I just need the correct syntax to write the statement.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 06:03:10
The condition can be placed
- in an update statement, but I dont' know what you want to do
- in a select statement, but I dont' know what you want to do
- in a WHERE clause, but I dont' know what you want to do

A trigger knows the "tables" inserted and deleted
inserted and deleted can hold more than one record at runtime so the value-check should consider this, but I dont' know what you want to do


I wish you good luck!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Guestuser18
Starting Member

34 Posts

Posted - 2009-11-05 : 06:07:18
if (:NEW.VALUE) BETWEEN 1 AND 6 THEN

Thats all I needed.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 06:11:08
But that's not a valid syntax in a trigger in T-SQL.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -