Hi Guys, I wonder if someone could help me with some SQL.
I have the following syntax:
SELECT
RIGHT(Ord.Contract, 4) AS Contract,
CASE WHEN Ord.Status IN ('10', '15') THEN '10/15' ELSE Ord.Status END AS ReqStatus,
Ord.Part,
Ord.[Order],
ISNULL(Ord.StartDate, Ord.DueDate) AS StartDate,
Ord.DueDate,
CASE WHEN RIGHT(Ord.Planner, 1) IN ('S','Z') THEN Ord.DueDate ELSE Ord.StartDate END AS MeasureDate,
Con.TypeCode
Inv.CommodityCode,
FROM ORD_ITEMS Ord LEFT OUTER JOIN
INVENTORY_MASTER Inv ON Ord.Part = Inv.Item LEFT OUTER JOIN
CONTRACT_HEADER Con ON Ord.Contract = Con.Contract
The question i ask is how do i put the following logic into the SQL statement, remembering MeasureDate is made up of other things.
Case When MeasureDate < getdate()-21 then 1 when MeasureDate > getdate()-22 and MeasureDate < getdate()+1 then 2 when MeasureDate > getdate() and MeasureDate < getdate()+31 then 3 when MeasureDate > getdate()+30 and MeasureDate < getdate()+93 then 4 else 5 end
Thanks
I have the following syntax:
SELECT
RIGHT(Ord.Contract, 4) AS Contract,
CASE WHEN Ord.Status IN ('10', '15') THEN '10/15' ELSE Ord.Status END AS ReqStatus,
Ord.Part,
Ord.[Order],
ISNULL(Ord.StartDate, Ord.DueDate) AS StartDate,
Ord.DueDate,
CASE WHEN RIGHT(Ord.Planner, 1) IN ('S','Z') THEN Ord.DueDate ELSE Ord.StartDate END AS MeasureDate,
Con.TypeCode
Inv.CommodityCode,
FROM ORD_ITEMS Ord LEFT OUTER JOIN
INVENTORY_MASTER Inv ON Ord.Part = Inv.Item LEFT OUTER JOIN
CONTRACT_HEADER Con ON Ord.Contract = Con.Contract
The question i ask is how do i put the following logic into the SQL statement, remembering MeasureDate is made up of other things.
Case When MeasureDate < getdate()-21 then 1 when MeasureDate > getdate()-22 and MeasureDate < getdate()+1 then 2 when MeasureDate > getdate() and MeasureDate < getdate()+31 then 3 when MeasureDate > getdate()+30 and MeasureDate < getdate()+93 then 4 else 5 end
Thanks