user3445262
user3445262

Reputation: 25

How do I find records based on month-name?

I have this query:

select dbo.CLOI_ClientOrderItems.cl_id,sum(dbo.IN_Invoices.in_total) as Total
from CLOI_ClientOrderItems
inner join IN_Invoices on CLOI_ClientOrderItems.MasterOrderId=IN_Invoices.MasterOrderId

where dbo.IN_Invoices.in_date_issued='2014-01-21 12:39:20.593'
group by cl_id

Instead of specifying the full date, I'd like to able to select the invoices issued in March, using something like this:

select dbo.CLOI_ClientOrderItems.cl_id,sum(dbo.IN_Invoices.in_total) as Total
from CLOI_ClientOrderItems
inner join IN_Invoices on CLOI_ClientOrderItems.MasterOrderId=IN_Invoices.MasterOrderId

where dbo.IN_Invoices.in_date_issued='march'
group by cl_id

How can I do that?

Upvotes: 0

Views: 57

Answers (3)

Amit
Amit

Reputation: 15387

Use DatePart for select the month only

select dbo.CLOI_ClientOrderItems.cl_id,sum(dbo.IN_Invoices.in_total) as Total
from CLOI_ClientOrderItems
inner join IN_Invoices on CLOI_ClientOrderItems.MasterOrderId=IN_Invoices.MasterOrderId

where DatePart(mm,dbo.IN_Invoices.in_date_issued)=3
group by dbo.CLOI_ClientOrderItems.cl_id

Upvotes: 1

Edper
Edper

Reputation: 9322

Use DATENAME():

select dbo.CLOI_ClientOrderItems.cl_id,sum(dbo.IN_Invoices.in_total) as Total
from CLOI_ClientOrderItems
inner join IN_Invoices on CLOI_ClientOrderItems.MasterOrderId=IN_Invoices.MasterOrderId

where DATENAME(month,dbo.IN_Invoices.in_date_issued)='March'
group by cl_id

Upvotes: 1

raguM.tech.
raguM.tech.

Reputation: 183

create instance for the following

public static final SimpleDateFormat FULL_DATE_TIME_FORMAT = new SimpleDateFormat(DD_MM_YYYY_HH_MM_SS_SSS_A);

object(FULL_DATE_TIME_FORMAT).parse("2014-01-21 12:39:20.593 Am");

Upvotes: 0

Related Questions