Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 use results from view in a where statement

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2013-09-13 : 16:48:56
I have a sql server 2008 stored procedure where I want to use the results of a view in a where statement. I want to check to see if the results from the view is not null.

The sql looks like the following currently:

select top 5 from cust_table
where view value is not null.

Would you show me the t-sql that I would need to use to see if the results from the view is null?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-09-13 : 17:12:12
You would join cust_table to the view and then specify your view condition.

select top 5 from cust_table c
join viewname v
on c.somecolumn=v.somecolumn
where view.somepossibleothercolumn is not null

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -