Solved

Remove last quoted identifier in a table column

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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