Solved

Remove last quoted identifier in a table column

Posted on 2011-03-17
5
384 Views
Last Modified: 2012-05-11
Hello ,

I need to remove the last quoted identifier (")in my table column.
I have quoted identiers at the beginning and the end of the values in the column but I need to remove only the last ones . Pls can some one show me how to use an update statement or something to do this in SQL

Many thanks

0
Comment
Question by:marvo2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 167 total points
ID: 35155761
try this

update tablename
set colname = LEFT(colname, (Len(colname)-1))
0
 
LVL 19

Assisted Solution

by:Rikin Shah
Rikin Shah earned 166 total points
ID: 35155778
This would help...
DECLARE @string varchar(50)
SET @string='some string"'
select LEFT(@string,LEN(@string)-1)

Open in new window

0
 
LVL 14

Assisted Solution

by:Daniel_PL
Daniel_PL earned 167 total points
ID: 35155962
Check this script, it'll show you whole process:
 
USE [tempdb]
--create test table
CREATE TABLE #test
(id INT IDENTITY(1,1),
data VARCHAR(32))

--load random data to test table
DECLARE @a TINYINT
SET @a=0
WHILE @a <= 200
BEGIN
	DECLARE @Length TINYINT
	DECLARE @RandomID varchar(32)
	DECLARE @counter smallint
	DECLARE @RandomNumber float
	DECLARE @RandomNumberInt tinyint
	DECLARE @CurrentCharacter varchar(1)
	DECLARE @ValidCharacters varchar(255)
	SET @ValidCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+&$'
	DECLARE @ValidCharactersLength int
	SET @ValidCharactersLength = len(@ValidCharacters)
	SET @CurrentCharacter = ''
	SET @RandomNumber = 0
	SET @RandomNumberInt = 0
	SET @RandomID = ''
	SET @Length = 30
	SET NOCOUNT ON
	SET @counter = 1
	WHILE @counter < (@Length + 1)
		BEGIN
			SET @RandomNumber = Rand()
			SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1))
			SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1)
			SET @counter = @counter + 1
			SET @RandomID = @RandomID + @CurrentCharacter
		END
	SET @RandomID='"'+@RandomID +'"'
	INSERT INTO #test VALUES (@RandomID)
	SET @a=@a+1
END

--select data from test table
SELECT * FROM #test

--update each row in test table by removing last ["] from string
UPDATE #test
SET data = LEFT(data,PATINDEX('%["]',data)- 1)

--see what was removed
SELECT * FROM #test

--drop test table
DROP TABLE #test

Open in new window

0
 

Author Comment

by:marvo2010
ID: 35156226
Thanks Guys . Two of you gave me the best replies that led me to the solution so I am going to share the points between both of . I do appreciate your help immensely.

Thanks alot

0
 

Author Comment

by:marvo2010
ID: 35156244
Actually three of you . Thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question