Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SELECT @Date= COUNT(Date),@Date= COUNT(Date) FROM TableName WHERE Date= @Date

SELECT COUNT(Date) AS Modified, Year(Date) Year,MONTH(Date) Month
FROM TableName
GROUP BY Year(Date),MONTH(Date) ORDER BY MONTH
Posted
Comments
PIEBALDconsult 17-Nov-15 8:42am    
Why? You probably need only an INSERT/SELECT -- try to avoid cursors whenever possible.

1 solution

See the comment from @PIEBALDconsult - do not use a cursor to do this.

If you want to create a new table from your query then simply use
SELECT COUNT([Date]) AS Modified, Year([Date]) [Year],MONTH([Date]) [Month]
INTO NewTable
FROM TableName
GROUP BY Year([Date]),MONTH([Date])

If NewTable already exists then do it this way instead
SQL
INSERT INTO NewTable
SELECT COUNT([Date]) AS Modified, Year([Date]) [Year],MONTH([Date]) [Month]
FROM TableName
GROUP BY Year([Date]),MONTH([Date])

Also not the square brackets [ ] around the column names Date and Month - this is because those words are reserved words in SQL - if you really cannot think of anything else to call the column you must indicate to SQL that you really mean the column name and not the reserved word.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900