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

Creating SQL Query with IF Statement in a View 1

Status
Not open for further replies.

mitchsrf

Programmer
Jul 10, 2001
3
US
I need a different query depending on what time of the day it is.

Using Query Analyzer, I can use IF statements to get the result I want. When I put that SQL query in a view and check the syntax it gives me errors. Is it possible for a VIEW in SQL Server 7.0 to contain SQL query with IF-ELSE statements?

Thanks.
 

It isn't possible use control of flow statemetns in a view. However, you might be able to use CASE statements to accomplish what you want. Or you can create a stored procedure and use IF... THEN... ELSE. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it if you have time.
 
also the view creator will choke on case statements, but they will work you just need to create the view manually. I usually use the view creator to do everything but the case statments and then add them manually.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top