Dynamic SQL is a technique using SQL (Structured Query Language) whose main difference from traditional SQL is that Dynamic SQL allows to build SQL statements dynamically at runtime, which eases the automatic generation and execution of program statements.
Questions tagged [dynamic-sql]
2681 questions
0
votes
2 answers
How to perform a dynamic select query for multiple tables in oracle? using table name and column names as values from other table?
i have a table having columns such schema name,table name,column name.
schema name
table name
column name
dbo
product
colour
dbo
sales
quantity
dbo
customer
order
i want to perform an action such that to get a count of records based…

Salva
- 81
- 1
- 9
0
votes
0 answers
Update statement in stored procedure with varbinary parameter
I have the following table:
CREATE TABLE NZQA_Unit(
NZQAUnitID int IDENTITY(1,1) PRIMARY KEY NOT NULL,
NZQAUnitNumber int NOT NULL,
Title nvarchar(255) NOT…

Álvaro
- 1,351
- 1
- 10
- 14
0
votes
1 answer
Dynamically Create SQL Columns using Table Rows
I have a extract that looks someting like this
| ID | NAME | ATTRIBUTE | VALUE |
| 1 | PENCIL | TYPE | HB2 |
| 1 | PENCIL | COLOR | RED |
| 1 | PENCIL | MADE IN | JAPAN |
| 1 | PENCIL | HAS ERASER| YES |
| …

Ivan Nel
- 319
- 3
- 12
0
votes
1 answer
Dynamic SQL mistakenly looks for table variable
my code accepts table name parameters and my dynamic code is supposed to query a table. I consistently get the error: @sourcetbl variable must be declared. After a lot of troubleshooting, I realized why I get error. SQL keeps assuming that I must…

NewbieOne
- 3
- 2
0
votes
1 answer
Create indexes for tables with prefix in PostgreSQL
I'm trying to achieve a way to create multiple indexes for multiple tables in Postgresql.
For now, i wrote something like this
do $$
declare temprow record;
declare idx_name character varying(200);
begin
for temprow in
select table_name from…

tty6
- 1,203
- 11
- 30
0
votes
1 answer
ORA-00904: "Good": invalid identifier ORA-06512
1.getting invalid identifier error while updating row_val variable char value 'Good' into the table
2.while inserting number it's working fine but strings its getting errors
3.
declare
count_temp number;
csv_data varchar2(1000);
val…

saisantosh
- 3
- 3
0
votes
1 answer
Execute Dynamic SQL with Concated Variables
I have multiple columns with names like "abc", "abc1", "abc2", "abc3".
My goal is to push the value to the next column, so:
abc3 = abc2
abc2 = abc1
abc1 = abc
abc = null
I wrote this:
DECLARE @name varchar(20)
SET @name = 'abc'
DECLARE @exec…
0
votes
1 answer
Dynamic SQL search improvement
I have this SQL query that I am using for dynamic search in the database:
SELECT [Name],[Vendor]
FROM OrderedApps
Where Name like '%' + 'Microsoft Visio' + '%' OR [Vendor] like '%' + 'Microsoft Visio' + '%'
In the database I have e.g.:
Name …

Tobi
- 5
- 2
0
votes
1 answer
sqlconcat two variables postgresql
Im writing a psql function. I want to do a concat between two variables inside psql.
and im getting syntax_error.
Let's notice that date_contract is of type date.
Thank you Who can help me
declare
result_table regclass :=…

dsp
- 141
- 6
0
votes
1 answer
Possible for Oracle PL/SQL to use dynamic procedure name?
I am trying to pass a loop the name of the procedure I want to call as I need to call 3 similar procedures in a row.
Lets call them:
Proc_A
Proc_B
Proc_C
They each have 1 input variable and 2 output variables.
Any ideas on what I can change to get…

user68288
- 702
- 2
- 6
- 27
0
votes
2 answers
Stored procedure : getting error "Must declare the scalar variable "@id". " when executing procedure
I need some help creating a stored procedure in SQL Server.
This is my code
CREATE PROCEDURE [dbo].[PROC_TABLE_ELEMENTS]
@id nvarchar(max)
AS
DECLARE @sql varchar(max) = '', @col_list varchar(max) = ''
SET @col_list = (SELECT DISTINCT…

Christian Lacuesta
- 43
- 1
- 1
- 5
0
votes
2 answers
Query to search in all columns in table with joining
I am searching in all column data in the selected SQL table, and I have a join with another table, but my issue that the 2nd table has the same column name with tableA, how can I specify each column with its table.
So I declare the string to find…

Med Amin
- 23
- 1
- 4
0
votes
2 answers
Execute query string and get result with varying number of columns
I am trying to transform a list of correlation values into a correlation matrix.
But I can't get the result after executing a string query.
The list/table(named corrtemp) is like this:
| name | colname | value |
| ---- | ------- | ----- |
| a | a…

sh12121212
- 1
- 1
0
votes
0 answers
I need to make this output more user friendly, write to a #Tmp table ideally
This query was from a 2017 post on this site and the results fit my requirements but I need them to a temp table. It currently writes to the screen with the column headers from each table and the values in each. When I try and insert it onto a temp…
0
votes
2 answers
Generating create stored procedure script using SQL syntax only
I am aware it is possible in SQL Server Management Studio to generate a create stored procedure script using the Object Explorer (right click on stored procedure, "Script stored procedure as...", Create To)
Is it possible to generate a create script…

Keybladerhuy
- 51
- 5