•
•
•
•
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
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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...
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.
•
•
Join Date: Sep 2006
Location: San Diego, CA USA
Posts: 99
Reputation:
Rep Power: 3
Solved Threads: 2
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.
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- ambiguous part 3 (C)
- Computed column in view VS trigger on update (MS SQL)
- Ms Sql Server 2000 (MS SQL)
- figuring out PK/FK (MS SQL)
- How does views work in MS SQL (MS SQL)
- Create View syntax problem (Oracle)
- call resultset in join query (JSP)
- need help creating user defined SQL statement (ASP.NET)
Other Threads in the MS SQL Forum
- Previous Thread: UPDATE rows WHERE array[] ?
- Next Thread: Need help in MS ACCESS VBA


Linear Mode