Solved

Updating ms sql with special characters

Posted on 2016-11-27
8
23 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 17

Expert Comment

by:Pawan Kumar Khowal
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 17

Expert Comment

by:Pawan Kumar Khowal
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
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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 17

Accepted Solution

by:
Pawan Kumar Khowal 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 2

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now