가능한 중복 :
Referring to a Column Alias in a WHERE Clausewhere 절에 별칭을 사용하려면 어떻게해야합니까?
SELECT
Trade.TradeId,
Isnull(Securities.SecurityType,'Other') SecurityType,
TableName,
CASE
WHEN
SecurityTrade.SecurityId IS NOT NULL
THEN
SecurityTrade.SecurityId
ELSE
Trade.SecurityId
END AS PricingSecurityID,
sum(Trade.Quantity)OVER(Partition by Securities.SecurityType, SecurityTrade.SecurityId,Trade.Price, Buy,Long) as sumQuantity,
--added porfolio id for Getsumofqantity
Trade.PortfolioId,
Trade.Price,
case
when (Buy = 1 and Long = 1) then 1
when (Buy = 0 and Long = 0) then 1
else 0
end Position
from
Fireball_Reporting..Trade
where porfolioid =5 and Position =1
내가 내 where 절에 위치 = 1을 사용하고자하는 경우
case
when (Buy = 1 and Long = 1) then 1
when (Buy = 0 and Long = 0) then 1
else 0
end Position
의 별칭은 내가 어떻게 할 수 where 절에서 사용 하시겠습니까?
내가 직접 나를
WHERE Trade.SecurityId = @SecurityId AND PortfolioId = @GHPortfolioID AND
(case when (Buy = 1 and Long = 1) then 1 when (Buy = 0 and Long = 0) then 1 else 0 end Position = 1)
외부 쿼리에 다른 select 및 check postion = 1을 추가하지 않는 이상 수 없습니다. –
어떤 SQL 언어를 사용하고 있습니까? – StingyJack
T SQL in sql server 2008 – Neo