DATETRUNC

ccparkhillccparkhill Posts: 24 Bronze 2
edited October 8, 2024 9:39AM in SQL Prompt
SQL prompt doesn't seem to handle DATETRUNC when formatting, instead of this:
SELECT DATETRUNC (YEAR, [d].[FullDate]) AS [YearStartDate] FROM [Dim].[Date] AS [d];

I get this, which errors when executed:
SELECT [DATETRUNC] ([YEAR], [d].[FullDate]) AS [YearStartDate] FROM [Dim].[Date] AS [d];
Tagged:

Best Answer

Answers

  • ccparkhillccparkhill Posts: 24 Bronze 2
    SQL prompt doesn't seem to handle DATETRUNC when formatting, instead of this:
    SELECT DATETRUNC (YEAR, [d].[FullDate]) AS [YearStartDate] FROM [Dim].[Date] AS [d];

    I get this, which errors when executed:
    SELECT [DATETRUNC] ([YEAR], [d].[FullDate]) AS [YearStartDate] FROM [Dim].[Date] AS [d];
  • Hi Chris,

    This seems to be working on the latest version of Prompt (10.14.23) and for an on-prem SQL Server


    Are you seeing this on a similar configuration or is it different? If its an earlier version of Prompt, could you check if upgrading to the latest version works?

    Sujay Diwan| Product Support Engineer | Redgate Software
  • ccparkhillccparkhill Posts: 24 Bronze 2
    Hi Sujay,

    I have the latest version, I'm using it against Azure SQL, here are my settings:

  • Hi Chris,

    Thank you for that. I was able to replicate the issue with Azure SQL database. I will escalate this to the development team to look into and will let you know as soon as there are any updates.
    Sujay Diwan| Product Support Engineer | Redgate Software
  • ccparkhillccparkhill Posts: 24 Bronze 2
    edited October 15, 2024 10:31AM
    Thanks Sujay, I am also seeing a similar issue when adding IGNORE NULLS to FIRST_VALUE:
    SELECT
        [d].[FullDate]
      , FIRST_VALUE ([d].[FullDate]) IGNORE NULLS OVER (PARTITION BY [d].[FinancialYear] ORDER BY [d].[FullDate]) AS [FinYearStartDate]
    FROM [Dim].[Date] AS [d]
    ORDER BY 1;

    SELECT
        [d].[FullDate]
      , FIRST_VALUE ([d].[FullDate]) [IGNORE] [NULLS] OVER ([PARTITION] BY [d].[FinancialYear] ORDER BY [d].[FullDate]) AS [FinYearStartDate]
    FROM [Dim].[Date] AS [d]
    ORDER BY 1;
  • Hi Chris,

    Thank you for the update.
    I have replicated this one as well on Azure SQL and have shared the details to the development team to look into.
    Sujay Diwan| Product Support Engineer | Redgate Software
  • Thanks, appears to be working fine.
Sign In or Register to comment.