2014-01-21 3 views
-1
원래

에 하위 쿼리는 :변환 SQL 쿼리/LINQ

select *, (PlanBasedOnDataUseage - CurrentPlanPricePerMonth) as MonthlyOverageInvoiceAmount from  

(  
Select * ,  

(select top 1 PricePerMonth from accounttypes where IsDeleted = 0 and AvailableOnline = 1  
and RecordsPerMonth > 0) as PlanBasedOnDataUseage  
,  
(select top 1 AccountTypeName from accounttypes where IsDeleted = 0 and AvailableOnline = 1  
and RecordsPerMonth > 0) as SuggestPlanBasedOnDataUsage  
from  
(  
select  
ClientID, ClientName, ClientEmail, AccountOwnerName,  
AccountExpiryDate,  
DATEADD(day, DAY(AccountExpiryDate)-1,  
CAST(  
    cast(YEar(GETDATE())as nvarchar(4)) +  
    replace(str(cast(Month(GETDATE())as nvarchar(2)), 2), ' ', '0') + '01'  
    as datetime)  
) as MonthlyRollOverDate  
, AT.RecordsPerMonth as CurrentPlanMentionsMaxPerMonth  
    , AT.AccountTypeName as CurrentPlanAccountType  
, AT.PricePerMonth as CurrentPlanPricePerMonth  
from clients C  
inner join AccountTypes AT on C.AccountTypeID = AT.AccountTypeID  
LEFT OUTER JOIN AccountOwner AO on AO.AccountOwnerID = C.AccountOwnerID 
WHERE  
AT.AccountTypeName not in ('Standard', 'Demo', 'Trial') and  
AccountExpiryDate > getdate()  
    AND  
    (  
    DATEADD(day, DAY(AccountExpiryDate)-1,  
    CAST(  
     cast(YEar(GETDATE())as nvarchar(4)) +  
     replace(str(cast(Month(GETDATE())as nvarchar(2)), 2), ' ', '0') + '01'  
     as datetime)  
    )  

    >=   
    --Monday Last Week  
    dateadd(d, -7, DATEADD(wk, DATEDIFF(wk, 0, GETDATE()), 0))  
    AND  
    --Calc MonthlyRollOverDate  
     DATEADD(day, DAY(AccountExpiryDate)-1,  
     CAST(  
     cast(YEar(GETDATE())as nvarchar(4)) +  
     replace(str(cast(Month(GETDATE())as nvarchar(2)), 2), ' ', '0') + '01'  
     as datetime)  
     )  
    <=  
    -- THis Monthday  
    DATEADD(wk, DATEDIFF(wk, 0, GETDATE()), 0)  



)  
) as ClientsRollingOverThisWeek  

) as ClientsRollingOverThisWeekWithRealPlanAttached  

where (PlanBasedOnDataUseage - CurrentPlanPricePerMonth) > 0  
+0

시도 http://www.sqltolinq.com/ – Nilesh

+0

적어도 우리에게 당신을 위해 당신의 일을하라고 요청하기 전에 직접 시도해보십시오. http://whataveyoutried.com/ – Basic

+3

http://bit.ly/1bMcoe0 – Smartis

답변

-1

당신은 LINQ 쿼리의 SQL 출력을 표시하는 Linqpad를 사용할 수 있습니다.

+0

LinqPad로 시도했지만 linq에 SQL을 변환 할 수 없습니다 –

+0

@Sourav가 정확합니다. Linqpad는 SQL을 LINQ로 변환하지 않습니다. 그러나 LINQ 쿼리의 SQL 출력을 보여줍니다. – webworm