July 22, 2014 at 10:31 am
I have to write a SQL script where one of the requirement is
DeliveryIDcharacters 1-7 not equal to 'aaaaaaa' AND
(If Today is Monday and 2nd character = M OR
If Today is Tuesday and 3rd character = T
If Today is Wednesday and 4th character = W
If Today is Thursday and 5th character = T
If Today is Friday and 6th character = F
If Today is Saturday and 7th character = S
If Today is Sunday and 1st character = S)
Do i have to use case statement or functions
July 22, 2014 at 10:51 am
This solution might be slow for large volumes of data but does what you need. Any option will be slow because you have seven values in one column and that's against the normalization rules. You're using at least 7 bytes of space when using a 7 bit columns will need less than one byte.
I'm assuming @@DATEFIRST = 7.
SELECT *
FROM (VALUES ('aaaaaaa'),
('SMTWTFS'),
('SaTWaFS'),
('SMaWaFS'),
('aMTWTFa'))x(schedule)
WHERE SUBSTRING(schedule, DATEPART(dw, GETDATE()),1) = LEFT( DATENAME( dw, GETDATE()), 1)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply