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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select data by month

Author  Topic 

siti
Starting Member

11 Posts

Posted - 2005-08-11 : 23:02:35
i have an application that stores data using dd/mm/yyyy format. how can i select data by month only?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-12 : 00:56:58
Which of the following do you want?

Select columns from yourTable where month(datecol)=monthvalue

Select month(datecol) from yourtable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2005-08-12 : 01:11:56
Select *
From tblYourTable
Where DATEDIFF(MM, dtiYourDateField, @dtiPassedInDate) = 0

Aj

Hey, it compiles.
Go to Top of Page

siti
Starting Member

11 Posts

Posted - 2005-08-12 : 03:54:28
i think i'll use the first one madhivanan.

Select columns from yourTable where month(datecol)=monthvalue

how should i write the monthvalue? eg: august or 8

Go to Top of Page

siti
Starting Member

11 Posts

Posted - 2005-08-12 : 04:06:49
aj,
what do you mean by @dtiPassedInDate
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-12 : 04:42:30
>>how should i write the monthvalue? eg: august or 8

Select columns from yourTable where month(datecol)=8


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

siti
Starting Member

11 Posts

Posted - 2005-08-12 : 05:45:31
i tried your opinion madhivanan but i get error like this:
error converting datetime statement to varchar statement
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-12 : 05:47:12
Post the table structure and the actual query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2005-08-12 : 10:05:13
I was assuming that you are passing in a date field to query against. If it just has to pull this months records then use this:

Select *
From tblYourTable
Where DATEDIFF(MM, dtiYourDateField, GETDATE()) = 0

And like madhivanan suggested, if we aren't giving you what you are looking for then go ahead and post the table structure.

Aj

Hey, it compiles.
Go to Top of Page

siti
Starting Member

11 Posts

Posted - 2005-08-18 : 01:36:28
thanks everybody... i've tried both solution and it worked. sorry because i send late reply. anyway...thank you so much.
Go to Top of Page
   

- Advertisement -