Error updating SQL query

The following query request error. Plz help me and tell me what error is.

This query saves the following result:

string sqlcmd = "UPDATE branch SET brac_subj = " + query_data + " WHERE (braid = "+dd_branch+")";

     UPDATE branch SET brac_subj = "'11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21'" WHERE (braid = 1) 

how can i save the string in the following format:

'11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21' 
+3
source share
5 answers

The problem you are working with in Enigma is called Escaping. Since single quotes are limited characters and determine the start of a string in SQL, you cannot use it as-inside the same string.

In addition to this, it looks like you are getting the impression that SQL Server is using double quotes to determine the row, which is not the case.

This syntax will not work:

UPDATE branch SET brac_subj = "'11' , '12' , '13'"

This syntax will work:

UPDATE branch SET brac_subj = '''11'' , ''12'' , ''13'''

, , , , .

, - select:

SELECT "'11' , '12' , '13'"

SELECT '''11'' , ''12'' , ''13'''
+2

, . :

query_data="'"+query_data.Replace("'","''")+"'";

"11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21". :

query_data="'"+query_data.Replace("'","")+"'";
+1

, "duncan o'toole", "duncan o''toole" sql-

0

, , , ..

UPDATE branch SET brac_subj = '11,12,13' WHERE (braid = 1)

,

UPDATE branch SET brac_subj = '"11","12","13"' WHERE (braid = 1)
0

- :

SET QUOTED_IDENTIFIER OFF

UPDATE branch SET brac_subj = "'11', '12', '13'"

When SET QUOTED_IDENTIFIER is enabled, identifiers can be separated by double quotes, and literals must be separated by single quotes. When SET QUOTED_IDENTIFIER is turned off, identifiers cannot be specified and must follow all Transact-SQL rules for identifiers. See Database Identifiers for more information .

0
source

All Articles