Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'if' stmt in a view

Status
Not open for further replies.

TheWkndr

Programmer
May 1, 2002
67
0
0
US
I don't know why I can't find anything about this, but how would one go about using an 'if' statement in a view?
Looking to show SN if FSN is blank. both are text fields.

Not sure when I turned dumb here. Thanks.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TheWkndr
 
You would have to use a CASE statement. Check it out in BOL or on-line.
 
if FSN is blank

Can you be more specific...

What is the data type for FSN?
What is the data type for SN?
When FSN is "blank", does this mean an empty string, or is it NULL?

If a "blank" FSN is really NULL, and the data types for FSN and SN are the same, then you could use the Coalesce function, like this....

[tt]
Select Col1,
Col2,
[!]Coalesce(FSN, SN) As SomeAliasName,[/!]
etc...
[/tt]

The Coalesce function will return the value in the first parameter if it is not NULL. If the first parameter is NULL, then it will return the value in the second parameter.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top