How to create a querystring in procedure to insert string with single and double quote

searchsanjaysharma
searchsanjaysharma used Ask the Experts™
on
I want to pass a string in procedure containing single quote and/or double quote
Ex:
My data entered in textbox is "I as 'as'  and as "India"

1/ How to pass this as parameter
2/ How to create querystring inside procedure


declare @qs nvarchar(max)
set qs=?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
lcohanDatabase Analyst

Commented:
declare @qs nvarchar(max)
set @qs='"I as ''as''  and as "India"';
print @qs;

Open in new window


single quotes in a string must be put as two single quotes to show a(1) single quote and double quote is ok as is.

Author

Commented:
No this i also know but this is of no use.
Topic Advisor, Page Editor
Distinguished Expert 2018
Commented:
Now, your string  "I as 'as'  and as "India" doenst make sense (to me) but you say above you already know that part....

But if you dont mind, please explain what that string represents to you, or, what you are wanting as a result.

If it is intended for use within a query, you would need to use Dynamic SQL if you want the procedure to effectively use the content of your parameter to use within a subsequent select query.

Or... You may also want to set quoted identifiers. When set to ON, anything in double quotes is an identifier (Table Name, Proc Name, Column Name….etc). See https://docs.microsoft.com/en-us/sql/t-sql/statements/set-quoted-identifier-transact-sql?view=sql-server-2017

Or, are you wanting to know how to call the Stored Procedure. Are you using a pass-through query, or ADO ?

Or, are you wanting something else ?

Please explain....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial