Andrés Bernardo
Andrés Bernardo

Reputation: 62

SQL Server quotation marks issue

I need to execute the following code (it's an example) in other server, but I having an issue with the quotations.

For more information, I'm getting the procedure code from a variable, so, it's static code, it's string.

Is there a way to execute it in the way it is?

SET QUOTED_IDENTIFIER OFF  
declare @query varchar(max)  
set @query="create procedure dbo.test as  select <1>"hola"<1> "
execute(@query) 
SET QUOTED_IDENTIFIER ON

Thanks

Upvotes: 0

Views: 142

Answers (2)

Jjcc
Jjcc

Reputation: 111

I do not understand well what you want I hope I help you

declare @query varchar(max)  
declare @char char = ''''
set @query='create procedure dbo.test as  select '+@char+'<1>"hola"<1> '+@char
--PRINT @query
execute(@query)

Upvotes: 1

SMor
SMor

Reputation: 2882

Don't use the double quote mark in tsql - ever. Learn how to nest single quote marks if you need to embed a string literal in a string. Given the trivial example, you have probably over-simplified the issues you are facing (or have yet to face). It may be that you are looking for the functionality. An example is here - you should be able to easily adapt that by replacing the [execute procedure] statement with a [create procedure] statement.

Upvotes: 0

Related Questions