Remove Last N Characters From Column

| |

Recently in a project to list all the plugins in a WordPress site with their versions I had accidently added .0 on to various rows in error.

This script was very helpful to correct this error

SELECT [id],
	[siteid],
	[pluginid],
	[versioninstalled],
	LEFT([versioninstalled], LEN([versioninstalled]) - 2),
	[Activated]
FROM [Documentation].[dbo].[tblWP_SiteToPlugin]
WHERE RIGHT([versioninstalled], 2) = '.0'
UPDATE [Documentation].[dbo].[tblWP_SiteToPlugin]
SET [versioninstalled] = LEFT([versioninstalled], LEN([versioninstalled]) - 2)
WHERE RIGHT([versioninstalled], 2) = '.0'

Reference: http://stackoverflow.com/questions/10470471/delete-last-n-characters-from-field-in-a-sql-server-database

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.