ajliaks
Hi guys,
How should I do, in order to retrieve the date field "Table1.ValueDate" with the format mm-yyyy
Cast (Table1.ValueDate
Thanks in advance,
Aldo.
Transact-SQL
You can do this like this:
SELECT REPLACE(convert(VARCHAR(7),GETDATE(),102),'.','-')
But to echo what Jen said, try if at all possible to do this on the client, unless this is need in some other capacity, like to feed another query.
>>but I think it's much more elegant than using a string to group.<<
Agreed. And I would also add that if this is for such usage, you probably would be best to add persisted computed columns to your table to "store" the month(dateInQuestion) and year(dateInQuestion) and use them. I was just going along the thought that it was in fact a formatting thing.