Problem:
I have a table with field values in double quotes, like: “blabla”.
Those quotes need to be removed for every field value, desired result: blabla
Tool:
SELECT '"TE"ST"',LEN('"TE"ST"')
SELECT REPLACE('"TE"ST"','"',''), LEN(REPLACE('"TE"ST"','"',''))
Output:
(No column name) (No column name)
"TE"ST" 7
(No column name) (No column name)
TEST 4
Solution:
DECLARE @I INT
DECLARE @MAX INT
DECLARE @STMT NVARCHAR(MAX)
DECLARE @TABLE NVARCHAR(MAX)
SET @TABLE='table_name'
SET @MAX=number_of_columns
SET @I=0
WHILE @I<=@MAX
BEGIN SET @STMT='
UPDATE '+@TABLE+'
SET [COLUMN '+CAST(@I AS NVARCHAR)+'] = REPLACE([COLUMN '+CAST(@I AS NVARCHAR)+'],''"'','''')
WHERE 1=1'
EXEC(@STMT)
SET @I=@I+1
END
Today on New Scientist: 4 January 2010
-
Today's stories on newscientist.com, at a glance, including: how exotic stars could mimic the big bang, a history of walking on water, and how to put leeches...
13 hours ago
0 comments:
Post a Comment