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
 General SQL Server Forums
 New to SQL Server Programming
 Displaying custom text, in a query

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-05-10 : 15:18:47
hi,

I am trying to create a union all query, right now it looks something like this:

Select id, title, page_id ,content from tblY
UNION all
Select id, title, NULL, country from tblX

but i want the results to also include a column that tells me which table the data came from.

is it possible?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-10 : 15:30:53
Select id, title, page_id, content, 'tblY' AS WhichTable
from tblY
UNION all
Select id, title, NULL, country, 'tblX'
from tblX

Or similar...

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

Subscribe to my blog
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-05-10 : 15:33:46
that worked, thanks!

i tried double quotes before and failed :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-10 : 15:34:13
You're welcome.

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 -