Reputation: 5727
i would like to create a sql query like these :
Select* from Table where
(if picod=1)
{
dvdt= "xxxx"
}
(if picod=2)
{
cddt= "xxxx"
}
(if picod=3)
{
bldt= "xxxx"
}
(if picod=3)
{
fadt= "xxxx"
}
I don't know how doing this in SQL .
Anyone could help me please ?
Thanks a lot :)
Upvotes: 1
Views: 126
Reputation: 1632
SELECT *
FROM Table
WHERE 'xxxx' = case Picod
when 1 then dvdt
when 2 then cddt
when 3 then bldt
when 4 then fadt
end
Upvotes: 0
Reputation: 69819
Just use OR
SELECT *
FROM Table
WHERE (Picod = 1 AND dvdt = 'xxxx')
OR (Picod = 2 AND cddt = 'xxxx')
OR (Picod = 3 AND bldt = 'xxxx')
OR (Picod = 3 AND fadt = 'xxxx');
Upvotes: 3
Reputation: 5912
Select* from Table
where (picod=1 and dvdt= 'xxxx') or (picod=2 and cddt= 'xxxx') or ....... (XXXX) or....
Upvotes: 4