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
 Help, conditional searching

Author  Topic 

Neon
Starting Member

13 Posts

Posted - 2012-01-19 : 21:13:45
hi all
first off i'll display example

i have a table similar to this
ID, TYPEID, VAL1, VAL2
1 1 4 2
2 1 2 3
3 2 3 4
4 2 4 5
5 1 3 2
6 1 3 5
7 3 5 1


ie, User input - TypeID 1,2 - VAL1 = 4 - VAL2 = 5

i need to select Type1 using VAL1 data Only, but VAL1 and VAL2 for TypeID 2

giving result of

ID, TYPEID, VAL1, VAL2
1 1 4 2
4 2 4 5
6 1 4 3

can this be done?
thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-20 : 13:29:51
Maybe something like this?:
SELECT *
FROM Table
WHERE
(
TypeID = 1
AND Val1 = 4
)
OR
(
TypeID = 2
AND
(
Val1 = 5
OR Val2 = 5
)
)
Go to Top of Page
   

- Advertisement -