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
 select of select

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2008-12-05 : 04:23:26
Hi i need a stored proc to do the follwing

select count(id) as rcount, DATENAME(MONTH,RDate)as GMonth
FROM Records_table
WHERE RCODE <> 'IN'
GROUP BY month(RDate)

but its not quite working
this is for a graph to show the count by month..

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-05 : 04:55:06
whats not working ? Is there an error when you run the query ? Or, You don't have the funtionality going ..Why stored proc ?? You have posted too little .. Elaborate, post sample data etc etc
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-05 : 05:58:35
select count(id) as rcount, DATENAME(MONTH,RDate)as GMonth
FROM Records_table
WHERE RCODE <> 'IN'
GROUP BY DATENAME(MONTH,RDate)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

craigmacca
Posting Yak Master

142 Posts

Posted - 2008-12-05 : 06:30:50
ok the results i am getting are incorrect

i have lots of month names, i have tried distinct by stull get simlar results

what i need is

Jan 07 556
feb 07 334
march 07 2323
Jan 08 454545

but i also need to group by the year aswell
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-12-05 : 06:43:20
Post Sample Data and Expected Output. That way we are not stabbing in the dark.

You've posted output but no dataset to work from.





Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-05 : 07:35:07
select count(id) as rcount, DATENAME(MONTH,RDate)as GMonthl,DATEPART(YEAR,RDate)as GYear
FROM Records_table
WHERE RCODE <> 'IN'
GROUP BY DATENAME(MONTH,RDate),DATEPART(YEAR,RDate)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -