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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have one more question for the da

Status
Not open for further replies.

vorvad

Technical User
Nov 21, 2001
9
0
0
US
I have one more question for the day.
I am having problems finding help on 'if else' constructs.

I want to do the following:

select cola if cola > colb else colb
from mytable

Thanks in advance!
VB
 
If... Else... Is used for control of flow in T-SQL. You should use the CASE statment in queries.

Select
Col=Case
When cola > colb
Then cola
Else colb
End
From mytable Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Here's one way:

Select (CASE When Cola > Colb then Cola else Colb END) as TheColumn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top