2

I have table Table1. With fields f1, f2

The table values are like that (values contains quotes)

 "Hello1", "ok1"
 "Hello2", "ok2"

I need a update query so that it will remove the quotes from the values and it should look like

 Hello1, ok1
 Hello2, ok2
7
  • What database system are you using? Commented May 3, 2011 at 21:59
  • There are a lot of SQL databases.. What database engine are you using? i.e. MySQL, PostgreSQL, Oracle, etc Commented May 3, 2011 at 22:01
  • @user310850 - Do we assume all of rows contain surrounding quotes? Or only some? Also, what version of SQL you're using? Commented May 3, 2011 at 22:01
  • @user310850 - What database product and version? I.e., MySQL, SQL Server, Oracle? Commented May 3, 2011 at 22:01
  • 1
    Just to clarify : do you want surrounding quotes to be removed? or ALL quotes? Commented May 3, 2011 at 22:04

5 Answers 5

3

Use the Replace function to strip out the double quotes.

UPDATE Table1 set f1 = REPLACE(f1,'"',''), f2 = REPLACE(f2,'"','');
Sign up to request clarification or add additional context in comments.

3 Comments

Can you write the full query to get tthe out put that i required please
After you run the update it's just a matter of Selecting the columns: SELECT f1, f2 FROM Table1
@user310850 that's the whole thing unless you want to add a where
2

If you want to remove only the surrounding quotes use :

UPDATE Table1 SET
f1 = SUBSTRING(f1, 2, LEN(f1)-2),
f2 = SUBSTRING(f2, 2, LEN(f2)-2)

If you want to remove all quotes (including middle ones) use :

UPDATE Table1 set f1 = REPLACE(f1,'"',''), f2 = REPLACE(f2,'"','')

Then to get the final output, you can use :

SELECT * FROM Table1

Comments

0

I think this might depend on the variety of SQL, but in MySQL you can do:

UPDATE Table1 SET f1 = TRIM(BOTH '"' FROM f1), f2 = TRIM(BOTH '"' FROM f2);

Comments

0

You can use substring and len to get only a part of the string.

Use this update statement to change the content of your table

update Table1 set
  f1 = substring(f1, 2, len(f1)-2),
  f2 = substring(f2, 2, len(f2)-2)

If you only want to change the output of a query you can do this

select
  substring(f1, 2, len(f1)-2),
  substring(f2, 2, len(f2)-2)
from Table1 

Comments

0
Update Table1
Set f1 = Case
            When f1 Like '"%' And f1 Like '%"' Then Substring(f1,2,Len(f1)-2)
            When f1 Like '"%' Then Substring(f1,1,Len(f1)-1)
            When f1 Like '%"' Then Substring(f1,2,Len(f1)-1)
            Else f1
            End
    , f2 = Case
            When f2 Like '"%' And f2 Like '%"' Then Substring(f2,2,Len(f2)-2)
            When f2 Like '"%' Then Substring(f2,1,Len(f2)-1)
            When f2 Like '%"' Then Substring(f2,2,Len(f2)-1)
            Else f2
            End

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.