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 |
rsheppick
Starting Member
5 Posts |
Posted - 2008-03-10 : 15:25:03
|
Greetings all...I have 38,000 rows of date fields called Month, in a table called IntRevenue.....Currently, I'm trying to do something simular to this however I cannot get it to work, the reason for this is a Report I am making...select DATENAME(m, [Rev Month])from IntRevenuewhere DATENAME(m, [Rev Month]) between 'April' and 'May'If I were to do April to April it shows me april fine, I guess it just doesn't know april is before may lol?Likely it is me just being stupid... |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-10 : 15:35:32
|
select DATENAME(m, [Rev Month])from IntRevenuewhere DATEpart(m, [Rev Month]) between 4 and 5 E 12°55'05.25"N 56°04'39.16" |
 |
|
rsheppick
Starting Member
5 Posts |
Posted - 2008-03-10 : 15:40:24
|
Msg 245, Level 16, State 1, Line 1Conversion failed when converting the nvarchar value 'June' to data type int.Month is DateTimeI guess because JUNE is char and I have ( Between 2 and 4 ) |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
rsheppick
Starting Member
5 Posts |
Posted - 2008-03-10 : 15:44:44
|
Doh, DATEPART haha sorry. |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-03-10 : 17:40:36
|
As Jeff pointed out, it is better to filter a date range on a start and end date.To select data for a particular month, do something like this:declare @StartOfMonth datetimedeclare @StartOfNextMonth datetimeset @StartOfMonth = '20070401'set @StartOfNextMonth = dateadd(mm,1,@StartOfMonth)select *from MyTableWhere -- Select dates on or after start of month MyDateColumn >= @StartOfMonth and -- Select dates before beginning of next month MyDateColumn < @StartOfNextMonth CODO ERGO SUM |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-11 : 02:36:36
|
A kind hard to do, if he wants all Aprils and Mays for all years? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|