troubleshooting Question

Correcting Sql Syntax to tally counts by month for a location

Avatar of mahpog
mahpog asked on
Sybase DatabaseSQL
6 Comments1 Solution447 ViewsLast Modified:
I have a table with a field called box location.  I have 4 different box locations. I want to simply the code, so I want to code the sql to do one location at a time.  
So, I am attaching my code below.
I want to do a count for box location = SMCBUYR from 01/01/08 through 06/30/08.
If there is no count for January, I want 0 displayed on my result set for January. (the reason for the second table called asrp_rpt_helper). Asrp_rpt_helper has YYMM dates ( 0801,0802,0803,0804...)

My current result set shows jan through june but no counts!
(attaching results)
finally my table has 6 records for SMCBUYR for the month of APRIL.

(attaching below).

select  substring(rptdate,3,2)+'/20'+substring(rptdate,1,2) mmyy,
	from a_smc, asrp_rpt_helper 
	where convert(datetime,date_rcvd) between convert(datetime,'080101') and convert(datetime,'080630')
	and rptdate *= substring(date_rcvd,9,2)+substring(date_rcvd,1,2)
	and rptdate between substring('080101',1,4)  and substring('080630',1,4)
	group by box_loc, rptdate 
	order by rptdate

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros