?
Solved

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

Posted on 2009-04-24
5
Medium Priority
?
240 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:RichardKline
  • 3
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24224637
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
 
LVL 1

Author Comment

by:RichardKline
ID: 24225392
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24225694
>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
 
LVL 1

Author Comment

by:RichardKline
ID: 24225858
Gotcha and I'm more impressed.  Can you tell me what the trailing "sq" represents?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24225958
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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question