[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Remove last quoted identifier in a table column

Posted on 2011-03-17
5
Medium Priority
?
389 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 668 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 664 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 668 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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