This is the query I have.I am trying to figure out how do I query this against multiple linked servers.I have 7 linked servers.
select count() from (select col1,col2,count()NoOfDiscounts
from tblname a
join tblname2 b
on a.columnID=b.columnID
where col1>0
and col2 is not null
group by col1,col2
having count(*)>1)a
I need help in this query,how do I concatenate col2 is not null in this dynamic query.If I removed this part query runs fine,but if i put this part,gives me an error 'near the keyword 'is'
set @sql='SELECT * from OPENQUERY('+@servername+',
''select count() from (select col1,col2,count()NoOfDiscounts
from tblname a
join tblname2 b
on a.columnID=b.columnID
where col1>0
and col2 is not null
group by col1,col2
having count(*)>1)a'