User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,506 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,664 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 2814 | Replies: 1
Reply
Join Date: Jun 2007
Posts: 2
Reputation: jberry is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jberry jberry is offline Offline
Newbie Poster

Help Create view with if statements?

  #1  
Aug 6th, 2007
Hi all,
I currently have a view in my database that pulls certain data from a table. The issue I run into is sometimes this table can be empty, and so I have an empty view.
I have been unsuccessful at using an IF statement inside of my view. Is it possible to have a statement such as this for the creation of my view...
if (select count(column) from table) > 0
select (column) from table
else
select (column) from table2
Last edited by jberry : Aug 6th, 2007 at 7:49 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Location: San Diego, CA USA
Posts: 99
Reputation: M_K_Higa is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster in Training

Re: Create view with if statements?

  #2  
Aug 9th, 2007
Have you considered puting this code in a stored procedure instead of a view? This type of code is easily implemented in a stored procedure.

If you require a view, then you may want to create a stored procedure to populate a separate table. This table can be populated according to the logic you describe. You would then view the populated table with a view.

If what I describe is acceptable for your needs and you need more information I can provide.
-Mike
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 4:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC