Is there a way to put a case argument in a from clause?

I am trying to choose from different places depending on a particular aspect. Is it possible to put an operator CASEin a sentence FROM?

This is what i am trying to do

FROM (Case WHEN @location = 'location A' THEN stockA 
WHEN @location = 'location B' then stockB end) ss

StockA is what I would pull out if I didn’t select several places. SS is an alias.

+4
source share
1 answer

You cannot do this. Here is a sorting method:

select ab.*
from ((select a.*
       from stockA a
       where @location = 'location A'
      ) union all
      (select b.*
       from stockB b
       where @location = 'location B'
      )
     ) ab
+8
source

Source: https://habr.com/ru/post/1539636/


All Articles