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
 Can we check 2 values in IN field ???

Author  Topic 

shikhakaul
Starting Member

5 Posts

Posted - 2009-04-01 : 19:34:58


i am very new to the topic

i have to check for 2 values ... can it be done using IN command

For e,g

productno. price
abc 123
xyz 123
ysh 231
abc 231


if i want first line as output and also this table is results from another table so you cannot do like productno like abc etc.. how do get it ?????

i hope i am able to explain

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-04-01 : 19:49:18
Are you referring to this:

WHERE productno IN ('abc', 'xyz')



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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

shikhakaul
Starting Member

5 Posts

Posted - 2009-04-01 : 20:05:09
No i want smtg like

where productno, price in (......)

chking for both
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2009-04-01 : 22:32:08
where productno in ('abc', 'xyz') and price in (123,231)
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2009-04-02 : 00:28:29
or if certain pairs need to go together:

where (productno='abc' and price=123) or (productno='xyz' and price=321)


elsasoft.org
Go to Top of Page

shikhakaul
Starting Member

5 Posts

Posted - 2009-04-02 : 15:59:37
hiii thanks for ur reply

but i cant use separate IN commands because it wont filetr that exact row..

and i cannot use = , because this table is result from another table....
Go to Top of Page

shikhakaul
Starting Member

5 Posts

Posted - 2009-04-02 : 16:00:37
where productno in ('abc', 'xyz') and price in (123,231) will not give me one row that i want abc 123
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2009-04-02 : 16:09:13
use exists and you won't have any problems like this.

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.5 out!
Go to Top of Page

shikhakaul
Starting Member

5 Posts

Posted - 2009-04-02 : 17:35:24
i cannot use = wbecause there are hundreds of rows and what value wil come in rows i dont know
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-03 : 03:11:07
quote:
Originally posted by shikhakaul

i cannot use = wbecause there are hundreds of rows and what value wil come in rows i dont know


Did you try spirit1's suggestion?


select columns from your_table as t
where exists (select * from other_table where productno=t.productno and price=t.price)



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -