sql server - How to use a newly defined column name in the where clause of a query in sql 2008 -


i have query in sql server 2008 like:

select t1.id,  matchids = (select dbo.getcommadelimitedstring(t2.id) #temp t2        t1.id != t2.id , t1.patientid=t2.patientid         , t1.hcn=t2.hcn        ) #temp t1 

this query has output like:

id   matchids 1    2,5,6 2    1,5,6 3    null 4    null 5    1,2,6 6    1,2,5 

what want rid of rows matchids null. when try add matchids not null clause main query, not accepting saying invalid column name matchidsand not want write same query used assign matchids in clause well. in case, best way provide it?

any appreciated.

just move query cross apply

select t1.id,         cs.matchids #temp t1 cross apply (select dbo.getcommadelimitedstring(t2.id) #temp t2        t1.id != t2.id , t1.patientid=t2.patientid         , t1.hcn=t2.hcn) cs (matchids) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -