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
 Nested Query from Range

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2010-12-08 : 19:14:02
Is this possible ? I did try to find an example pattern.

Select fieldA, B from table1 where fieldA =
( Select fieldA from table2 where C between 100 and 200 )

Thanks !

andrewcw

jessiefun
Starting Member

35 Posts

Posted - 2010-12-08 : 22:58:13
That will be no problem when there is no more than one record returned for the subquery
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2010-12-09 : 00:49:50
Are you saying it cannot be done for multiple values without resorting to building a "Or" e.g.

Select fieldA, B from table1 where fieldA =
X or fieldA = Y or fieldA = Zn ?

andrewcw
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2010-12-09 : 01:05:42
[code]select A, B from @t1 where A in (select A from @t2 where C between 100 and 200)[/code]


Am I missing something?

Nathan Skerl
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2010-12-09 : 01:12:06
SOLVED:
I believe this pattern is correct ( if I transposed it correctly for my tables & fields...) note the "in" and the parenthesis...

Select fieldA, B from table1 where ( fieldA in
( Select fieldA from table2 where (C between 100 and 200 )))


andrewcw
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2010-12-09 : 01:14:15
Thanks ... Nathans... your reply coincided with my finding an example I had sometime ago !!! This forums is great !

andrewcw
Go to Top of Page
   

- Advertisement -