How to solve this Query in Sql Server [Resolved]

Posted by Jayakumars under Sql Server on 6/2/2015 | Points: 10 | Views : 360 | Status : [Member] [MVP] | Replies : 2
Hi
My Table and data like this

Create Table Monthtable
(
Dateval Date
)

Insert into Monthtable values('06/07/2015')
Insert into Monthtable values('06/08/2015')
Insert into Monthtable values('06/09/2015')
Insert into Monthtable values('06/10/2015')
Insert into Monthtable values('06/11/2015')
Insert into Monthtable values('06/12/2015')
Insert into Monthtable values('06/13/2015')



DayNames DayNo
============================
Sunday 1
Monday 2
Tuesday 3
Wednesday 4
Thursday 5
Friday 6
Saturday 7


-- But I need output like this

DayNames DayNo
============================
Monday 1
Tuesday 2
Wednesday 3
Thursday 4
Friday 5
Saturday 6
Sunday 7

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 6/2/2015 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
SET DATEFIRST 1; --this sets Monday to the first day of the week for the current connection.

SELECT DATENAME(WEEKDAY,Dateval)DayNames, DATEPART(WEEKDAY,Dateval) DayNo, * FROM MonthTable
Order by DayNo


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 6/2/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down

Resolved
Hi

SET DATEFIRST 1; --this sets Monday to the first day of the week for the current connection.
SELECT DATENAME(DW,Dateval)DayNames, DATEPART(DW,Dateval) DayNo, * FROM MonthTable
Order by DayNo

Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response