Friday, February 17, 2012

Database parameter in SQL Server 2005

Hello,

I'm try'n to create a check "IF" in SQL (sql server 2005) to a database parameter and not from the code (@.Attend for example)

But the thing is I don't know how to perfume a check "IF" with a database parameter I'm used to check parameters from the code like this:

IF(@.Attend = 1)

Begin

.

.

.

End

Select

But now I know it has to be in the Select but the question is how?

Thanks,

Nadin

The CASE method may work for you but that's just a guess based on the information you've given. If that doesn't work, you will have to provide more details on exactly what you want and an example of your data structure.

|||

It depends on what you are trying to do. You can do this:

IF @.Attend = 1 SELECT ...ELSE SELECT

Or you can do this:

SELECT CASE ( WHEN @.ATTEND=1 THEN'ATTEND' WHEN @.ATTEND=0 THEN'NO ATTEND' ELSE'UNKNOWN') As AttendText
 
Note that you only need the BEGIN and END if you have multiple statements in your if block, or if you like them for readability (just like the { and } in c++/c#)
Or you could even write a UDF to translate the number to a string if it's really complicated.

No comments:

Post a Comment