Solved

Updating ms sql with special characters

Posted on 2016-11-27
8
64 Views
Last Modified: 2016-11-28
We need to update a column with characters that also include the apostrophe, for example

UPDATE tablename SET String1='/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû' WHERE column1='blah'

Open in new window


We need to save the value '/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû'  to the table.

How can we do this?
0
Comment
Question by:rayluvs
[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
  • 4
  • 3
8 Comments
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41903657
So the above query is not working ?

Replace ' to ''
0
 

Author Comment

by:rayluvs
ID: 41903661
It's only the apostrophe that is the problem?  (what about  those other characters: ñõ'âÜÀÿ'ôû?
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41903663
Try...

1. Single ' to '' which are present in between of the string.

'/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû' --------->  N'/tƒÉÄk…Bz–ñõ''âÜ(sÀ\ÿ$K''ylôû'  

2. Use N before the string you want to update
N'/tƒÉÄk…Bz–ñõ''âÜ(sÀ\ÿ$K''ylôû'

3. The column should be of NVarchar type.

CREATE TABLE tests
(
	column1 NVARCHAR(MAX)
)
GO

INSERT INTO tests VALUES (N'blah'),(N'Pawan')

UPDATE a
SET a.column1 =  N'/tƒÉÄk…Bz–ñõ''âÜ(sÀ\ÿ$K''ylôû'
FROM tests a
WHERE column1 = 'blah'

SELECT * FROM tests

Open in new window



O/P


column1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû
Pawan

(2 row(s) affected)

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41903666
Update..

2. N before the string is not required is the data type is of type Varchar. It is required if it is of type NVarchar.
3. The column can be of NVarchar or Varchar.


Hi rayluvs,
Is this done :) ?

Regards.,
Pawan
0
 

Author Comment

by:rayluvs
ID: 41903682
So there is no other way to update without replacing all ' within the value?

Finally, the special characters ñõ'âÜÀÿ'ôû, there is no problem saving them to the table? Any consideration?
(we are using a encryption/decryption in vb prior saving to the table routine and that is why those strange value... we want to make sure that those random characters are ok to save or is there any other additional considerations?)
0
 
LVL 29

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41903690
try this .. It is working for me..


SET QUOTED_IDENTIFIER OFF;

DECLARE @Str AS VARCHAR(1000) = "'/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû'"

UPDATE a
SET a.column1 =  @Str
FROM tests a
WHERE column1 = 'blah'

select * from tests

Open in new window



Output


column1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'/tƒÉÄk…Bz–ñõ'âÜ(sÀ\ÿ$K'ylôû'
Pawan

Open in new window

0
 

Author Comment

by:rayluvs
ID: 41903758
Yes!!! U D MAN!

Thanx!
0
 
LVL 3

Expert Comment

by:Ed Dredd
ID: 41903776
blue arrow uses two single quotes while the red arrows are one double quote

-11-28-2016-5-27-57-PM.png
For variables in the SQL, everytime you find a single quote replace it with two single quotes

REPLACE('@variables' , " ' " , " ' ' ");
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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