I have the following snippet code:
WHERE (Person.WorkGroupId = 2 or Person.RoleId = 2)
What I would like to happen is for this to return the first occurrence with a WorkGroupId
of 2 on Person table. But, if there is not a person with a WorkgroupId
of 2, then choose the first occurrence with RoldId
of 2 on the Person table.
Thanks
SELECT TOP (1) * FROM
(
SELECT TOP (1) *, o = 1
FROM Person
WHERE WorkGroupId = 2
UNION ALL
SELECT TOP (1) *, o = 2
FROM Person
AND RoleId = 2
) AS x ORDER BY o;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With