To escape ' you simly need to put another before: ''
As the second answer shows it’s possible to escape single quote like this:
select 'it''s escaped'
result will be
it's escaped
If you’re concatenating SQL into a VARCHAR to execute (i.e. dynamic SQL), then I’d recommend parameterising the SQL. This has the benefit of helping guard against SQL injection plus means you don’t have to worry about escaping quotes like this (which you do by doubling up the quotes).
e.g. instead of doing
DECLARE @SQL NVARCHAR(1000) SET @SQL = 'SELECT * FROM MyTable WHERE Field1 = ''AAA''' EXECUTE(@SQL)
try this:
DECLARE @SQL NVARCHAR(1000) SET @SQL = 'SELECT * FROM MyTable WHERE Field1 = @Field1' EXECUTE sp_executesql @SQL, N'@Field1 VARCHAR(10)', 'AAA'
Related Posts:
- What characters do I need to escape in XML documents?
- Illegal Escape Character “\”
- What characters must be escaped in HTML 5?
- How can I selectively escape percent (%) in Python strings?
- How do I escape a single quote in jQuery?
- How to escape apostrophe (‘) in MySql?
- Should HTML output be passed through esc_html() AND wp_kses()?
- How to prevent escaping when saving HTML code in an option value?
- How to correctly escape query variables to be used in WP_Query
- esc_attr / esc_html / esc_url in echos
- When do I need to use esc_html()? [duplicate]
- what’s different between esc_attr, htmlspecialchars and htmlentities
- Allow all attributes in $allowedposttags tags
- When outputting a static string to the page, is it necessary to escape the output?
- How Flexible are the WordPress Coding Standards for PHPCS?
- why is esc_html() returning nothing given a string containing a high-bit character?
- How to properly escape a translated string?
- Translate a Constant while appeasing WordPress PHPCS
- Using esc_url() on a url more than once
- Do I need to escape get_theme_mod(‘url’) / (‘mail’) with esc_url?
- How to allow   with wp_kses()?
- Using esc_attr_e
- Why esc_html_() is not used on every text that has a translation (on Twenty Twenty One)?
- Escaping crashes my output
- How to safely escape the title attribute
- How to safely escape data that contains HTML attributes
- Can wp_strip_all_tags be used as a substitute for esc_url, esc_attr & esc_html?
- Echoing a URL to a link
- wp_kses_post escaping doesn’t appear to work as described?
- file_get_contents | escaping doesnt show the page
- Help about Escaping
- How to keep specific tag from an html string?
- Escaping Issues
- Escaping and Special Characters (e.g. &)
- Escaping get_option( ‘time_format’ ) is nesserary?
- How should esc_url be combined with trailingslashit?
- Correct way of using esc_attr() and esc_html()
- What is a stored procedure?
- outputting ascii table in C++
- SQL Server: Difference between PARTITION BY and GROUP BY
- Conversion failed when converting date and/or time from character string while inserting datetime
- error, string or binary data would be truncated when trying to insert
- The SQL OVER() clause – when and why is it useful?
- What is the difference between char s[] and char *s?
- SQL Server Management Studio, how to get execution time down to milliseconds
- How do I escape a single quote in SQL Server?
- How Stuff and ‘For Xml Path’ work in SQL Server?
- Understanding the difference between null and ‘\u000’ in Java
- How can I convert const char* to string and then back to char*?
- The multi-part identifier could not be bound
- How to join two tables by multiple columns in SQL?
- Sql Server string to date conversion
- Find all tables containing column with specified name – MS SQL Server
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How can I import an Excel file into SQL Server?
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- SQL Server IF NOT EXISTS Usage?
- How to join two tables by multiple columns in SQL?
- Comparing chars in Java
- What represents a double in sql server?
- How do I fix ‘Invalid character value for cast specification’ on a date column in flat file?
- SELECT DISTINCT on one column
- What does it mean to escape a string?
- Comparing the values of char arrays in C++
- vs shell installation has failed with exit code 1638
- Convert char array to single int?
- TSQL PIVOT MULTIPLE COLUMNS
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Why do table names in SQL Server start with “dbo”?
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- Equivalent of Oracle’s RowID in SQL Server
- Subtract one day from datetime
- How to get the ASCII value in JavaScript for the characters [duplicate]
- XOR in SQL Server
- Backup a single table with its data from a database in sql server 2008
- Conditional JOIN Statement SQL Server
- Temporary table in SQL server causing ‘ There is already an object named’ error
- What datatype should be used for storing phone numbers in SQL Server 2005?
- SQL WHERE.. IN clause multiple columns
- Filter data based on date in sql
- Difference between esc_url() and esc_url_raw()
- Escaping WP_Query tax_query when term has special character(s)
- Do I need to escape data passed to wp_localize_script()?
- Prevent add_shortcode from escaping a tag
- Sanitizing comments or escaping comment_text()
- Prevent escaping javascript in visual editor
- Is it safe and good practice to use do_shortcode to escape?
- Unexpected esc_html and esc_attr behaviour
- should I escape a literal url added in functions.php
- How to allow single quote with esc_html__() without sprintf()
- Wrapping add_query_arg with esc_url not working
- wordpress post not showing my “” text>?
- How to make MySQL search queries with quotes
- Escaping WP_Query tax_query when term has special character(s)
- Escape html structure in php
- Allow iframe in custom meta box
- Escaping data from database (users table) is necessary?
- how to escape alert/window.location.replace with variable
- Is it necessary to use escape functions on everything or is it only necessary if you’re taking input from a 3rd party? (End Users, APIs, Etc.)