I would like to something like the following in SQL Server, is this possible?
SELECT *
FROM (
if (val == 0)
table1
else
table2
)
Nothing like this seems to work, how would you accomplish this?
I would like to something like the following in SQL Server, is this possible?
SELECT *
FROM (
if (val == 0)
table1
else
table2
)
Nothing like this seems to work, how would you accomplish this?
Just union
your 2 queries together and use the parameter condition in the where
clause e.g.
SELECT *
FROM table1
WHERE @Val = 0
UNION ALL
SELECT *
FROM table2
WHERE @Val <> 0;
Assuming Val
should be @Val
(i.e. a variable). The logic doesn't make sense if its a column.
IF EXISTS (SELECT * FROM table1 where @Val = 0)
BEGIN
SELECT * FROM table1
END
ELSE
BEGIN
SELECT * FROM table2
END