Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 458.6k

How to get 3 months limit of a data in sql server?

Jul 9 2024 4:00 PM

Hi Team

I have view and want to get 3 months limit, want to use single query in excel that will populate this so that when i refreshed the spreesheet i get current date of these months. Here is my below, logic.

 

Create View [dbo].[vw_Adr_Batch_Recipe_Log] AS
SELECT TOP (1000) [idx]
      ,[dt]
      ,[BatchNrA]
      ,[BatchNrB]
      ,[BatchNrC]
      ,[Recipe]
      ,[RecipeCode]
      ,[RecipeDescription]
      ,[InstructionNo]
      ,[Shift]
  FROM [Adroit_Batch_Suite].[dbo].[Adr_Batch_Recipe_Log]
  WHERE [dt] >= DATEADD(Month, -3, GetDate());

SELECT 
    idx,
    dt,
    BatchNrA,
    BatchNrB,
    BatchNrC,
    Recipe,
    RecipeCode,
    RecipeDescription,
    InstructionNo,
    Shift
FROM dbo.vw_Adr_Batch_Recipe_Log
WHERE dt >= DATEADD(month, -3, GETDATE());

 


Answers (4)