Is it possible to SELECT varName FROM ('Comma','Separated','Variables')

I'm trying to draw up a list of common values from database tables on different servers.  

Simplifying the issue a bit, is it possible to do something akin to the code sample?

I understand that reversing the SELECTS would work (referencing the array on line 5) but I have a situation specific reason for trying this way first..

Thank you.
SELECT thisValue 
   FROM ('1111','2222','3333')
   WHERE thisVALUE IN (
      SELECT thisOtherValue 
         FROM TableName )

Open in new window

LVL 1
RichardKlineAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
it is possible:
SELECT thisValue 
   FROM (select '1111' thisValue union all select '2222' union all select '3333') sq
   WHERE thisVALUE IN (
      SELECT thisOtherValue 
         FROM TableName )

Open in new window

0
 
RichardKlineAuthor Commented:
Thanks!
I bet that you're a whiz at Trivial Pursuit (The Database Edition).  
Do you happen to have a reference page which explains this syntax in detail?  
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Do you happen to have a reference page which explains this syntax in detail?  
not that I know. it's kind of a "combined knowledge" kind of info ....

0
 
RichardKlineAuthor Commented:
Gotcha and I'm more impressed.  Can you tell me what the trailing "sq" represents?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the "sq" is the alias name for the SubQuery  ...
sql server does require in several situations to have that for ( select ), so I just take the habit of putting it every time for a sub-query...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.