Solved

Updating ms sql with special characters

Posted on 2016-11-27
8
55 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
  • 4
  • 3
8 Comments
 
LVL 28

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 28

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 28

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 28

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tempdb log keep growing 7 44
SQL Recursion 6 33
Applying Roles in Common Scenarios 3 17
T-SQL: How to extract records into a new table 6 13
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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