-1

谁能帮我将此 Microsoft 访问查询转换为 Tsql 2008:

SELECT
    dbo_Invoiceable__c.NAME AS Invoiceable,
    dbo_Invoiceable__c.Payment_is_due__c,
    dbo_Invoiceable__c.Day_Due__c,
    DATE () AS [Invoice Date],
    DateSerial(Year(DATE ()), Month(DATE ()), [Day_Due__c])
        AS [On a day of the month],
    DateAdd("d", [day_due__c], DATE ())
        AS [In a given number of days],
    DateAdd("d", [day_due__c] - 1, DateAdd("m", 1, DateSerial(Year(DATE ()), Month(DATE ()), 1)))
        AS [No of days after EOM],
    IIf([Payment_is_due__c] = "In a given number of days", [In a given number of days], "") & IIf([Payment_is_due__c] = "On a day of this month", [On a day of the month], "") & IIf([Payment_is_due__c] = "No of days after EOM", [No of days after EOM], "")
        AS [Due Date]
FROM dbo_Invoiceable__c;

我试过这个:

SELECT *,
       CASE 
WHEN [Payment_is_due__c] = 'In a given number of days' THEN [In a given number of days] ELSE '' 
END + CASE 
WHEN [Payment_is_due__c] = 'On a day of this month' THEN [On a day of the month] ELSE '' 
END + CASE 
WHEN [Payment_is_due__c] = 'No of days after EOM' THEN [No of days after EOM] ELSE '' 
END AS [Due Date]
FROM   (SELECT [SalesForce_LIVE.dbo.Invoiceable__c].[Name] AS Invoiceable,
               [SalesForce_LIVE.dbo.Invoiceable__c].[Payment_is_due__c],
               [SalesForce_LIVE.dbo.Invoiceable__c].[Day_Due__c],
               CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1) AS [Invoice Date],
               dbo.DateSerial(Year(CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1)), Month(CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1)), [Day_Due__c]) AS [On a day of the month],
               DATEADD(d, [day_due__c], CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1)) AS [In a given number of days],
               DATEADD(d, [day_due__c] - 1, DATEADD(m, 1, dbo.DateSerial(Year(CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1)), Month(CONVERT (DATETIME, CONVERT (VARCHAR, GETDATE(), 1), 1)), 1))) AS [No of days after EOM]
        FROM   SalesForce_LIVE.dbo.Invoiceable__c) AS Nested1;  

但仍然无法让日期序列在 Tsql 中工作

4

1 回答 1

0
DECLARE @firstdayofmonth datetime;
DECLARE @lastdayofmonth datetime;
SET @firstdayofmonth =  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()),  0);
SET @lastdayofmonth =   DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0));

SELECT *,
     CASE  WHEN [Payment_is_due__c]='In a given number of days' THEN [In a given number of days] ELSE '' END + 
     CASE  WHEN [Payment_is_due__c]='On a day of this month' THEN [On a day of the month] ELSE '' END + 
     CASE  WHEN [Payment_is_due__c]='No of days after EOM' THEN [No of days after EOM]     ELSE '' END AS [Due Date] 
FROM  (SELECT SalesForce_LIVE.dbo.Invoiceable__c.[Name] AS Invoiceable,     SalesForce_LIVE.dbo.Invoiceable__c.[Payment_is_due__c], SalesForce_LIVE.dbo.Invoiceable__c.[Day_Due__c],
CONVERT(DATETIME,CONVERT(VARCHAR,GETDATE(),1),1) AS [Invoice Date],
DATEADD(DAY,[day_due__c],@firstdayofmonth-1) AS [On a day of the month], 
DATEADD(DAYOFYEAR,[day_due__c],CONVERT(DATETIME,CONVERT(VARCHAR,GETDATE(),1),1)) AS     [In a given number of days],
DATEADD(DAY,[day_due__c],@lastdayofmonth) AS [No of days after EOM] 
FROM SalesForce_LIVE.dbo.Invoiceable__c
 ) AS Nested1
于 2013-02-27T00:39:01.663 回答