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
 Date question

Author  Topic 

Rasta Pickles
Posting Yak Master

174 Posts

Posted - 2012-07-03 : 10:00:26
How do I add an extra field to my output, containing yyyymm?

The query I inherited started with the line

SELECT CONVERT(CHAR(6), EFFECTIVE_DATE, 112) AS Month,


but if I use it in it's present format, SQL protests that it must be contained in a GROUP BY clause.......ok, no big deal except the query returns over 8 million records and takes ten minutes to run.

If I comment out the line, I get 110,000 records which is much more preferable.

So is there a way to add a line to the SELECT part to add yyyymm to the output?

Thanks in advance!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-07-03 : 10:12:41
Are you grouping by CONVERT(CHAR(6), EFFECTIVE_DATE, 112), or just the effective_date?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Rasta Pickles
Posting Yak Master

174 Posts

Posted - 2012-07-03 : 10:59:17
Just by the effective date.

Did I do wrong?
Go to Top of Page
   

- Advertisement -