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)
 stored procedure -- if statement

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-03-06 : 04:18:34
I am trying to do an if statement in a stored procedure but I am new to this.

I have 3 separate fields in my db duplicate,nogood,filtered
I want to pull out these fields and if duplicate,nogood, or filteterd =1 then set status=that fieldname otherwise set status=good

can someone help me with the code I would use?

nr
SQLTeam MVY

12543 Posts

Posted - 2005-03-06 : 07:02:38
if is a control of flow statement - you need case.

select status = case when duplicate = i then 'duplicate' when nogood = 1 then 'nogood' when filtered = 1 then 'filtered' else 'good' end
fromtbl


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -