sql server 2008 - SQL Group by Year -


this query.

select convert(varchar, cast(date datetime), 3) shoptransfer  group year (date) 

i want group year part of date (varchar) column, following error:

column 'shoptransfer.date' invalid in select list because not contained in either aggregate function or group clause.

how group year part of date column?

how about:

select datepart(yyyy, [date]) [year] shoptransfer  group datepart(yyyy, [date]) 

or:

select count(*) qty, datepart(yyyy, [date]) [year] shoptransfer  group datepart(yyyy, [date]) order [year] 

this based on op's command: "i want group year part of date (varchar) column"


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

c# - how to write client side events functions for the combobox items -

ssh client with paramiko (python) -