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 2005 Forums
 Transact-SQL (2005)
 How to match based on part of a datetime field?

Author  Topic 

PingTheServer
Starting Member

28 Posts

Posted - 2009-02-25 : 17:54:39
I am trying to group by a piece of the date field, this is using SQL in Informix.

My query thus far looks like this:

select count(*) as Renewals, branch
from mv_idecal i, cr_newcar n
where i.id = c.id
and renewalmonth between "2009-01-01 00:00:00" and "2009-01-31 23:00:00"
group by i.branch
order by i.branch


I would like to not have to run this query for 2 years worth of data for this and similar queries.

Is there a way I can use just the year and month for the selection criteria? I think I can cast or convert it and use like or matches, but I'm not sure and I want to be sure it doesnt make any changes to the database.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-25 : 17:56:05
Since you are using Informix, then I would highly recommend that you post on a site that specializes in that dbms since sqlteam.com specializes in Microsoft SQL Server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

PingTheServer
Starting Member

28 Posts

Posted - 2009-02-25 : 17:56:13
that should read i.id = n.id
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-25 : 17:56:39
quote:
Originally posted by PingTheServer

that should read i.id = n.id



You can edit your post using the pencil icon.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -