I have a view that is using this syntax below. it works fine but I have to change the date manually everytime I want to see new results.
SELECT dbo.Customer.CustomerCode AS [CUST.ID], dbo.Customer.Name AS [CUST.NAME], dbo.CustomerAddress.City AS [CUST.SHORTADDR],
dbo.CustomerAddress.Address1 AS [CUST.TEXT01],
dbo.CustomerAddress.Address2 + ' , ' + dbo.CustomerAddress.Address2 + ' , ' + dbo.CustomerAddress.County AS [CUST.TEXT02],
dbo.JourneySODetail.DeliveryPostCode AS [CUST.POSTCODE], dbo.DeliveryArea.Name AS [CUST.TEXT03], dbo.Customer.CustomerCode AS [CALL.ID],
'D' AS [CALL.TYPE], dbo.JourneySODetail.TotalVolume AS [CALL.USER01], dbo.JourneySODetail.TotalWeight AS [CALL.USER02], CONVERT(varchar,
dbrderHeader.DateRequired, 103) AS [CALL.TEXT01], '08:00' AS [CALL.TEXT02], '17:30' AS [CALL.TEXT03],
REPLACE(REPLACE(dbrderHeader.SpecialInstructions, CHAR(13), ' '), CHAR(10), '') AS [CALL.TEXT04], dbrderHeader.CustomerRef AS [CALL.TEXT05],
dbrderHeader.OrderNumber AS [CALL.TEXT06], 0 AS [CALL.USER03]
FROM dbrderHeader INNER JOIN
dbo.CustomerAddress ON dbrderHeader.DeliveryAddressID = dbo.CustomerAddress.CustomerAddressID INNER JOIN
dbo.JourneyHeader ON dbrderHeader.JourneyID = dbo.JourneyHeader.JourneyID INNER JOIN
dbo.Customer ON dbrderHeader.CustomerID = dbo.Customer.CustomerID INNER JOIN
dbo.DeliveryArea ON dbrderHeader.DeliveryAreaID = dbo.DeliveryArea.DeliveryAreaID INNER JOIN
dbo.JourneySODetail ON dbrderHeader.OrderID = dbo.JourneySODetail.OrderID
WHERE (CONVERT(varchar, dbrderHeader.DateRequired, 103) = '08/04/2016')
I would like to apply something like the below for the dbrderHeader.DateRequired. I have tried to apply it but the more I try I get deeper into issues, could some kind person show me how to add the code in please. I will continue trying in the meantime. Thanks
SELECT FORMAT(
-- dates start on Sunday (1) and go to Saturday (7)
DATEADD(day,
-- number of days to add
CASE DatePart(Weekday,GetDate())
WHEN 1 THEN 1
WHEN 2 THEN 0
WHEN 3 THEN 6
WHEN 4 THEN 5
WHEN 5 THEN 4
WHEN 6 THEN 3
WHEN 7 THEN 2
END,
-- date to add them to
GETDATE()
),
-- the formatting code can use any combination of d, M and y
'dddd dd MMMM yyyy'
)
SELECT dbo.Customer.CustomerCode AS [CUST.ID], dbo.Customer.Name AS [CUST.NAME], dbo.CustomerAddress.City AS [CUST.SHORTADDR],
dbo.CustomerAddress.Address1 AS [CUST.TEXT01],
dbo.CustomerAddress.Address2 + ' , ' + dbo.CustomerAddress.Address2 + ' , ' + dbo.CustomerAddress.County AS [CUST.TEXT02],
dbo.JourneySODetail.DeliveryPostCode AS [CUST.POSTCODE], dbo.DeliveryArea.Name AS [CUST.TEXT03], dbo.Customer.CustomerCode AS [CALL.ID],
'D' AS [CALL.TYPE], dbo.JourneySODetail.TotalVolume AS [CALL.USER01], dbo.JourneySODetail.TotalWeight AS [CALL.USER02], CONVERT(varchar,
dbrderHeader.DateRequired, 103) AS [CALL.TEXT01], '08:00' AS [CALL.TEXT02], '17:30' AS [CALL.TEXT03],
REPLACE(REPLACE(dbrderHeader.SpecialInstructions, CHAR(13), ' '), CHAR(10), '') AS [CALL.TEXT04], dbrderHeader.CustomerRef AS [CALL.TEXT05],
dbrderHeader.OrderNumber AS [CALL.TEXT06], 0 AS [CALL.USER03]
FROM dbrderHeader INNER JOIN
dbo.CustomerAddress ON dbrderHeader.DeliveryAddressID = dbo.CustomerAddress.CustomerAddressID INNER JOIN
dbo.JourneyHeader ON dbrderHeader.JourneyID = dbo.JourneyHeader.JourneyID INNER JOIN
dbo.Customer ON dbrderHeader.CustomerID = dbo.Customer.CustomerID INNER JOIN
dbo.DeliveryArea ON dbrderHeader.DeliveryAreaID = dbo.DeliveryArea.DeliveryAreaID INNER JOIN
dbo.JourneySODetail ON dbrderHeader.OrderID = dbo.JourneySODetail.OrderID
WHERE (CONVERT(varchar, dbrderHeader.DateRequired, 103) = '08/04/2016')
I would like to apply something like the below for the dbrderHeader.DateRequired. I have tried to apply it but the more I try I get deeper into issues, could some kind person show me how to add the code in please. I will continue trying in the meantime. Thanks
SELECT FORMAT(
-- dates start on Sunday (1) and go to Saturday (7)
DATEADD(day,
-- number of days to add
CASE DatePart(Weekday,GetDate())
WHEN 1 THEN 1
WHEN 2 THEN 0
WHEN 3 THEN 6
WHEN 4 THEN 5
WHEN 5 THEN 4
WHEN 6 THEN 3
WHEN 7 THEN 2
END,
-- date to add them to
GETDATE()
),
-- the formatting code can use any combination of d, M and y
'dddd dd MMMM yyyy'
)