August 16, 2012 at 7:16 am
I'm using union to show records from the same table from different databases like
Select 'Firm1' as Company, b, c, d
from Dataset1.Table
where b like '%smth%'
union
Select 'Firm2' as Company, b, c, d
from Dataset2.Table
where b like '%smth%'
Union works but it only shows values when record exists.
How to make it that even if there is no record (let say in dataset2) it will show record with the name 'Firm2' and for instance 0 values for b,c,d.
Thank you for your help.
August 16, 2012 at 8:38 am
Pretty sparse on details but I think you want to use a left join instead of a union.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply