-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to query selected Months records
PostPosted: Thu Mar 24, 2011 7:04 am 
Newbie

Joined: Wed Aug 18, 2010 6:43 am
Posts: 10
Hi All

Can anyone please tell me how to query for a selected month's records. I have a query below that selects all records of current month but I need some thing which fetches all records of selected month (as a Parameter).

Code:
@NamedQuery(name = "Invoice.findByMonth", query = "SELECT  i FROM Invoice i WHERE month(to_date(to_char(i.invoiceDate, 'DD-Mon-YYYY'))) = month(to_date(to_char(sysdate, 'DD-Mon-YYYY')))"),


Many thanks

Zed


Top
 Profile  
 
 Post subject: Re: How to query selected Months records
PostPosted: Thu Mar 24, 2011 9:48 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Code:
SELECT  i FROM Invoice i WHERE month(i.invoiceDate) = :month


This query selects all Invoices for a given month of year (for all years).

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: How to query selected Months records
PostPosted: Tue Mar 29, 2011 6:20 am 
Newbie

Joined: Wed Aug 18, 2010 6:43 am
Posts: 10
Thank you mmerder that has worked, this is how I used it. I'm sure there was a better way of doing it in BEAN but this is how I did it.
Code:
@NamedQuery(name = "Invoice.findByInvoiceForWholeMonth", query = "SELECT  i FROM Invoice i WHERE month(i.invoiceDate) = :month")

Code:
public List<Invoice> getInvoiceByWholeMonth(Integer month) {
      em.getTransaction().begin();
      List<Invoice> invDate = em.createNamedQuery("Invoice.findByInvoiceForWholeMonth")
      .setParameter("month", month).getResultList();
      em.getTransaction().commit();
      return invDate;
   }


In Bean
Code:
String string= invoiceObj.getInvoiceDate().toString();
        String d = string.substring(6, 7);
        int date = Integer.parseInt(d) ;
      invoiceList = hibernateQueryManagerDao.getInvoiceByWholeMonth(date);   


Many Thanks
Zed


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.