Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-11-25 : 04:46:16
|
Hi All I need some help Aim – To work out what day of the week a Closedate Falls onDate format is of Closedate is “Year-month-Day” (varchar(50)For eg2013-11-252013-11-212013-11-192013-11-18Desired results 2013-11-25 Monday 2013-11-21 Thursday2013-11-19 Tuesday2013-11-18 MondayLooking forward to your help RegardsD |
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-11-25 : 04:52:12
|
I have Created the following query(See below) but i am recieving the following error message Msg 241, Level 16, State 1, Line 1Conversion failed when converting date and/or time from character string.select DATEPART(weekday, 'CloseDate')AS WEEKDAYfrom #buildwhere [StageName] in ('Unable to Approve', 'Opportunity Lost')and year([CloseDate]) = '2013'and [Channel Indicator] = 'Field'and MONTH([CloseDate]) = '10'order by CloseDate desc Bu |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 05:07:18
|
it should beselect DATEPART(weekday, [CloseDate])AS WEEKDAYfrom #buildwhere [StageName] in ('Unable to Approve', 'Opportunity Lost')and year([CloseDate]) = '2013'and [Channel Indicator] = 'Field'and MONTH([CloseDate]) = '10'order by CloseDate desc ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 05:29:07
|
quote: Originally posted by masond HI Visakh16Currently your soultions provides me with 1-7, is there anyway that i can state that 1 = monday, 2 = tuesday etc ? Also is there a function which enables me to find out what week number that is ?for eg closedate = '31/10/2013' is weeknum 44
SELECTDATENAME(weekday, [CloseDate])AS WEEKDAY,DATEPART(wk,[CloseDate])AS WEEKNOfrom #buildwhere [StageName] in ('Unable to Approve', 'Opportunity Lost')and year([CloseDate]) = '2013'and [Channel Indicator] = 'Field'and MONTH([CloseDate]) = '10'order by CloseDate desc ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|