Questions tagged [sp-executesql]

sp_executesql is a system stored procedure in Microsoft's SQL Server product range (2005 onwards) for running dynamic SQL.

sp_executesql is a system stored procedure in Microsoft's SQL Server product range (2005 onwards).

It is used for running dynamic T-SQL Statements or batches, including support for embedded parameters.

It is also what the .NET framework uses for ad-hoc queries when parameters are added to a SqlCommand.


Articles

235 questions
0
votes
2 answers

Create table in by sql statement using executeUpdate in Mysql

I have the following doGet(): protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MysqlDataSource ds = new MysqlConnectionPoolDataSource(); …
URL87
  • 10,667
  • 35
  • 107
  • 174
0
votes
3 answers

Set variables in stored procedure using EXECUTE sp_executesql

I'm trying to build an SQL string to execute via sp_executesql but I can't seem to assign value to a declared variable within the passed in sql string. So below is an example of my procedure ALTER PROCEDURE [dbo].[selectRecords] @psID INT…
Sun
  • 4,458
  • 14
  • 66
  • 108
-1
votes
1 answer

Why sometimes sp_executesql can be used in function sometimes not?

I have code in a SQL Server function: CREATE FUNCTION mpc.fun1 (@exp NVARCHAR(30))--@exp like '2*5/4' RETURNS DECIMAL(20, 10) AS BEGIN DECLARE @result decimal(13,4) DECLARE @str nvarchar(30)=N'SELECT @aOUT = 1.0 *' + @exp EXECUTE…
Alison Niu
  • 64
  • 3
-1
votes
1 answer

SSIS package Execute SQL task dynamic SQL (not SP) with multiple returns but only capture final variable

I have an SSIS package that is executing dynamic SQL. The Dynamic SQL will sometimes have result set and sometimes not, but I only want to capture the COUNT, which is the returned value in below script. (or can I use C# Script task to accomplish…
Brad
  • 3,454
  • 3
  • 27
  • 50
-1
votes
3 answers

Why NVarchar(MAX) cannot execute complete dynamic query using SP_ExecuteSQL?

I created a stored procedure that will have two queries, those two queries will update records in two tables. So I will mention what it shows My procedure is like below ALTER PROC UpdateMissingItemONPoe @StoreID INT, @Name…
Liam neesan
  • 2,282
  • 6
  • 33
  • 72
-1
votes
2 answers

TSQL Evaluate expressions in table of concatenated strings

I have a table with constructed strings like below. Is there any way to execute each constructed string and store the result in another field within the row? ROW 1 'SELECT NAME FROM ZC_ETHNIC_GROUP WHERE INTERNAL_ID = 4' ROW 2 'SELECT NAME…
jch
  • 187
  • 3
  • 17
-1
votes
1 answer

syntax issue with sp_executesql

I'm trying to write a stored procedure and I keep getting this error that I haven't defined @address , which I did. I know I'm missing a little thing , how should I change this? CREATE PROCEDURE search_domaintable @link nvarchar(50), @address…
-1
votes
1 answer

How sp_executesql with select?

Please. I need to run a stored procedure that is stored in a temporary table. I have two tables: create table pruebaa ( cam1 integer primary key, cam2 varchar(20) ) insert into pruebaa (cam1, cam2) values (1, 'valor1'); insert into pruebaa…
-1
votes
3 answers

Like search in execute_sql not working properly

I'm facing a very strange behavior of a like search within a sp_executesql: This statement returns 0 rows: exec sp_executesql N'SELECT * FROM MyTable WHERE Name LIKE ''%'' + @Name + ''%''',N'@Name nvarchar(7)',@Name=N'100024​' When this…
user1416197
  • 155
  • 1
  • 7
-1
votes
2 answers

sp_executesql gives unclosed quotation mark error?

I've written simple stored procedure and executing using sp_executesql to tackle with quotation error and sql injection as well but when i pass a single quote in parameter still it shows me Unclosed quotation mark after the character string…
Vishwanath Dalvi
  • 35,388
  • 41
  • 123
  • 155
1 2 3
15
16