CREATE PROCEDURE sp_stripDoubleQuotes
@tableName sysname,
@columnName sysname,
@SQL varchar(MAX)
AS
BEGIN
SET NOCOUNT ON;
SET @SQL =
'UPDATE ' + '[' + @tableName +']' +
'SET' + '[' + @columnName +']' +'= SUBSTRING(' +'[' + @columnName +']' +', 2, LEN(' +'[' + @columnName +']' +'))
WHERE LEFT(' + '[' + @columnName +']' +', 1) = '+'''"'''
--PRINT(@SQL)
EXEC (@SQL)
SET @SQL =
'UPDATE ' + '[' + @tableName +']' +
'SET' + '[' + @columnName +']' +'= SUBSTRING(' + '[' + @columnName +']' +', 1, LEN(' + '[' + @columnName + ']' +')-1)
WHERE RIGHT(' + '[' + @columnName +']' +', 1) = '+'''"'''
--PRINT(@SQL)
EXEC (@SQL)
END
GO
exec [dbo].[sp_stripDoubleQuotes] N'test', N'id' -- exec [dbo].[sp_stripDoubleQuotes] N'[dbo].[test]', N'[id]'
Updated 2nd: I added []
to wrap the table and column if there are spaces in your table and column name. Thanks @Sean Lange and @Richard
3rd: @[benjamin moskovits] (xD), , exec [dbo].[sp_stripDoubleQuotes] N'test', N'id'
. print
, , .