문제

I'm trying to select from different locations depending on a certain aspect. Is it possible to put a CASE statement in the FROM clause?

Here's what I'm trying to do

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

StockA is what I would be pulling it from if I wasn't selecting multiple locations. SS is the alias.

도움이 되었습니까?

해결책

You cannot do this. Here is a sort-of-close 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top