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
 General SQL Server Forums
 New to SQL Server Programming
 Query not working with between condition

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2012-05-14 : 06:07:30
I have query like this

Select NVL(SUM(TRANS_QTY),0) FROM IC_TRAN_PND where ITEM_ID IN (130,131) and line_type=1 AND COMPLETED_IND=1 AND
to_date(TRANS_DATE,'DD-MON-YY') Between to_date('01-JAN-12','DD-MON-YY') and to_date(('04-JAN-12'),'DD-MON-YY')

this query not returning the total sum of records between the two date ranges.

Do I need to convert something.

Regards

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-14 : 06:14:11
This is a Microsoft SQL Server forum.
If you have Oracle questions, please make them over at www.dbforums.com

In general, when sorting and searching date values, format them in ISO style YYYY-MM-DD

Select NVL(SUM(TRANS_QTY), 0)
FROM IC_TRAN_PND
where ITEM_ID IN (130, 131)
and line_type = 1
AND COMPLETED_IND = 1
AND to_date(TRANS_DATE, 'YYYYMMDD') Between to_date('01-JAN-12', 'YYYYMMDD') and to_date('04-JAN-12', 'YYYYMMDD')




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -