Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Want to retrieve 'Y' if my date range has week end , or 'N' if the date range has no weekend

SQL
declare @start datetime;
set @start = '2014-12-21';

declare @end datetime;
set @end = '2014-12-27';


SQL
SELECT 
-- The code should go here


This should return 'Y' Because this date range has a week end. (Saturday or Sunday)
Posted

Hi Here is your complete solution please check.


SQL
Declare @Start DATETIME
declare @end DATETIME
DECLARE @ans nvarchar(1)

SET @Start='2014-12-6'
SET @end='2014-12-15'

WHILE @Start <= @end
BEGIN

if((select DATENAME(dw,@Start))='Saturday' or (select DATENAME(dw,@Start))='Sunday' )
BEGIN
SET @ans='Y'
BREAK
END
ELSE 
BEGIN
SET @ans='N'
END
SET @Start=DATEADD(day,1,@Start)
END 

PRINT @ans
 
Share this answer
 
Comments
Gihan Liyanage 15-Dec-14 2:44am    
Thank you very much ..
Anisuzzaman Sumon 15-Dec-14 3:00am    
You are most welcome :)
See the answer at this[^] page.

/ravi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900