How exec a string like query in Sql Server? Dynamic Sql

In Sql Server you can exec a string like sql, for make it you shall use a stored procedure called sp_sqlexec.

In the nex code I write a query like string and the next line exec the string like query:

declare @cadena varchar(max)='select * from a_table'
 
exec sp_sqlexec @cadena

You should be careful with this stored procedure, as it could allow sql injection.

About

View all posts by