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

TSQL Optional Parameters that work on the same field

I have a stored procedure where I pass in a product type (prod_type) as a parameter up to four times. Potentially each of these parameters may be null, in which case they should be ignored. They should have a OR operator between each product type so…
0
votes
2 answers

T-SQL EXEC versus sp_exec

I tried the following: declare @var2 nvarchar(30) declare @qsql nvarchar(100) set @var2 = N'iddelegat' exec ('select max('+ @var2 + ') as IDexec from delegat'); set @qsql = 'select max(@varsp) as IDspexec from delegat'; exec sp_executesql @qsql,…
0
votes
4 answers

Inserting data dynamically in Temporary table by Select Statement only

I want to insert dynamic record in temporary table. I don't want to declare this table. I want its columns to be defined at run time. I am doing this because definition of table "Contract" may change in future. So temporary table(#x) should be…
Arjun
  • 431
  • 2
  • 8
  • 21
0
votes
0 answers

SSRS reports time out on dynamic queries after a few days

We're using SSRS 2012 with a number of reports driven by a Query.CommandText reference to a stored procedure executing dynamic sql (sp-executesql). These are consumed from a web application where the user specifies the report, criteria, etc. After a…
Reuven Trabin
  • 451
  • 7
  • 18
0
votes
1 answer

Reduce recompilation , sp_execute

I'm terrible with the problem on my servers when the problem of recompilation of queries, we report on this server, which are necessary for dynamic queries, researching a solution to this problem I got here. CREATE TABLE YEAR_YEAR (Y…
0
votes
1 answer

sp_executesql syntax error

I am trying to learn and use the sp_executesql and I am stuck even with this simple SQL statement. DECLARE @sql NVARCHAR(MAX) = NULL DECLARE @WHERE NVARCHAR(MAX) = NULL SET @sql = N' SELECT * FROM MyTable …
TTCG
  • 8,805
  • 31
  • 93
  • 141
0
votes
2 answers

Getting access to a dynamic table from dynamic sql

Good day StackOverflow The table that I create from my dynamic sql can have any number of columns as it is a pivot table. -- Pivot the table so we get the UW as columns rather than rows DECLARE @SQL NVARCHAR(MAX) SET @SQL = ' SELECT * FROM…
Bobby
  • 2,830
  • 3
  • 19
  • 36
0
votes
1 answer

phpMyAdmin dynamic sql - how to use?

Does dynamic SQL work in phpMyAdmin? I tried the most basic examples from http://www.youtube.com/watch?v=MiAwOoelu9k For instance, each of these throws an error (tried separately): EXEC ('SELECT data FROM table') EXEC sp_executesql N'SELECT data…
0
votes
2 answers

Need help to debug T-SQL stored procedure that has sql scripts stored in a table

In this stored procedure, I read from a third party vendor table named M_SopInsert. SQLScript is the column name and every record in this table contains a SQL query that does an UPDATE, INSERT or DELETE. I can see the actual script when I debug it…
0
votes
2 answers

calling a remote sproc from a function

I have a stored procedure SprocA resides on ServerA. SprocA takes 4 parameters, executes a dynamic sql and returns a record with 1 column (1 integer value). I'd like to be able to call this from a function FnB on ServerB so that I can use it in a…
T L
  • 504
  • 2
  • 11
  • 27
0
votes
3 answers

Fully qualified table names with SP_ExecuteSql to access remote server

Trying to update a table on a linked server (SQL 2000/2005) but my server name will not be known ahead of time. I'm trying this: DECLARE @Sql NVARCHAR(4000) DECLARE @ParamDef NVARCHAR(4000) DECLARE @SERVER_NAME VARCHAR(35) SET @Sql =…
Dlongnecker
  • 3,008
  • 3
  • 25
  • 40
0
votes
1 answer

Dynamic "INSERT INTO" Query with User Defined Type

I have got a SQL-Table were eache line consists a singel Value of some kind of Virtuel-Tabel - means the real existig SQL-Table looks like this: ----------------------------------------- |DataRecordset | DataField | DataValue …
0
votes
0 answers

PhoneGap - How to query SQLite in a for loop?

I have a problem with a SQLite query on PhoneGap application. I would open a folder and make a select with where clause for every entries in the folder. I open a for loop, after a select query, but the script uses same variables for all the entries…
ilPas
  • 21
  • 3
0
votes
2 answers

How to run a dynamic sql for each row of a table?

I have a table which contains a column named WhereClause DECLARE @UserGroups TABLE (WhereClause nvarchar(1000), totalCount int) The table has been populated with some values for WhereClause but none for totalCount column. An example of the…
The Light
  • 26,341
  • 62
  • 176
  • 258
0
votes
1 answer

T-SQL:exec() & sp_executedsql can't work with inserted & deteleted as input parameters

In my table there are three or more columns stored image file path, so I need to store the image file path to an specify table 'OnDeleteFile' when the data is going to delete,then the program to delete file in web server in task methord from this…
user1862341
  • 171
  • 1
  • 9
1 2 3
15
16