Solved

Remove last quoted identifier in a table column

Posted on 2011-03-17
5
378 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
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Detach & Attach 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now