Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How do I update the value of the entire column to the last day of the month.
for example. Currently its 2015-09-01. Update to 2015-09-30.
Just an FYI - I have more than 500 dates to update.
Posted
Comments
[no name] 16-Sep-15 12:55pm    
How is about to use Google?
https://www.google.ch/#q=mssql+last+day+of+the+month[^]
I'm for 99% sure you will find an answer.

Quote: "Just an FYI - I have more than 500 dates to update": I don't hope you think this 500 is something like "a lot of rows" ;)

If all the row values contain the first day of some month, just add one month and go back one day. So something like
SQL
UPDATE TableName
SET DateColumn = DATEADD(month, 1, DateColumn ) - 1;

For more information, see DATEADD[^]
 
Share this answer
 
Since you're using SQL 2012, you can use the new EOMONTH[^] function:
SQL
UPDATE YourTable
SET YourColumn = EOMONTH(YourColumn)
 
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