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
0 answers
Is there a way to select one column from a Dynamic SQL statement that falls within particular boundaries
SQL Server:
ALTER PROCEDURE [dbo].[Test_Pagination_Proc]
@DBNAME nvarchar(200),
@STOREDPROC nvarchar(200),
@INDEX int,
@PageSize int
/*
DECLARE @DBNAME nvarchar(200) = 'C110_victoribasco18_gmail'
,@STOREDPROC…

Victor Ibasco
- 11
- 3
0
votes
1 answer
PL SQL Oracle Store Dynamic SQL result (Dynamic in a loop)
I'm new to PL/SQL on Oracle (have to do some work on this but it's clearly not my domain).
So I have to do an 'audit' of our DB which consists in giving for each column of each table of our schema its max length (how we declared it (VARCHAR2(15) for…

Thomas
- 1
0
votes
1 answer
Oracle PLSQL wrong number or types of arguments in call to 'BIND_ARRAY' in DBMS_SQL
I've written the below PLSQL block.
However when i execute it , i am getting following error.
Kindly tell me how to pass nested tables in the DBMS_SQL to
execute and generate the report.
Can we use DBMS_SQL to pass array value to bind
parameters…

Gautam S
- 41
- 1
- 1
- 7
0
votes
1 answer
How to compose a psycopg2 dynamic SQL statement that includes functions on column names? e.g.: json_col::text
I need to compose a dynamic SQL statement, which includes certain functions on column names.
E.g.: SELECT json_col::text, SUBSTRING ( string_col ,1 , 2 ) FROM TABLE
Since the column names are enclosed in "", I keep getting undefined column…

aaaaa
- 11
- 1
0
votes
1 answer
Using tablenames from a config table for joins
SELECT
$model_master_id$,
$model_market_segment$,
$country$,
$ctry_cd$,
$score_run_id$,
$period_id$,
$prediction_from_dt$,
$prediction_to_dt$,
$buy_acq$,
$eval_prd$,
$scr.model_score$,
…

Reshmi Nair
- 11
- 4
0
votes
1 answer
Joining on table value in database
I have a table that holds a relationship of the id to the actual name of the joining table, I need to be able to get the actual table name out with an ID value. example:
TableID TableName
1 Test.Customers
2 Test.Orders
3 …

Tim Boland
- 10,127
- 8
- 27
- 25
0
votes
0 answers
Postgres while insert from md5(variable) it inserts column name not column values
below is my postgres procedure
create or replace procedure ds_rs.test_ad () as $$
declare
i integer;
v_command text;
rcd record;
v_count text; v_pk_1 text; v_pk_2 text;
v_account_id varchar(100);
v_query text;
begin
for rcd in ( select t.table_name…
0
votes
1 answer
How to append strings in PL/pgSQL?
I have a procedure that queries schema and table. I want this to not overwrite the variable instead append, because the result I want to create view.
DECLARE
rec record;
sqlPlaceholder text;
BEGIN
FOR rec IN SELECT table_schema,…

hi4ppl
- 595
- 1
- 6
- 21
0
votes
0 answers
What is the merit of prepared statement in mysql
After I read about prepared statement,I can set prepared statement like following.
It worked, but I haven't understood what is the merit of prepared statment. because I wonder what is the merit beyond normal sql in prepared statment ?
SELECT…

Heisenberg
- 4,787
- 9
- 47
- 76
0
votes
1 answer
Dynamix SQL Error "Must declare the scalar variable"
I have the @inAdd1-6 and @inAdd declared. The @inAdd1-6 will actually be passed into the Stored Procedure.
I will then split them and process the addresses, some as a single address, and others where I compare names, street, zip codes, etc.
I was…

Dizzy49
- 1,360
- 24
- 35
0
votes
2 answers
SQL Server stored procedure parameters syntax error
I have the following query:
DECLARE @periodEnd datetime = '2021-12-09 02:41:42.000'
DECLARE @ID VARCHAR(50) = '35915D4B-E210-48C0-ADD5-C68AAEB62C36'
EXEC('SELECT COUNT(*) AS count FROM pageloads nolock WHERE domainId = ''' + @ID+ ''' AND paid = 1…

billi j
- 7
- 3
0
votes
0 answers
Mysql Dynamic SQL is not allowed in stored function or trigger
To not publicly disclose our amount of invoices, we want to add random value between 2 ids.
Instead of [1,2,3] we want something like [69,98,179]
UUID is not an option in that project, unfortunately.
Using Mysql 5.7, 8, or MariaDb get the same…

Joel AZEMAR
- 2,506
- 25
- 31
0
votes
1 answer
Looping through table and column combinations
I need to make a script that goes through all tables, and select those columns where
name is specified.
I can find the columns where names are specified,
SELECT sys.columns.name AS ColumnName, tables.name AS TableName
FROM sys.columns
JOIN…

I am not Fat
- 283
- 11
- 36
0
votes
1 answer
Postgresql function to create table with dynamic table name?
Let's say I have several users, each with their own set of contacts. Users get to select which 3rd parties have access to their contacts.
I could maybe create 1 large contact table and have an 'owner' column so that I can identify which contacts…

a_coder
- 11
- 1
- 4
0
votes
0 answers
Where to add and declare variables to use them in dynamic SQL?
I have created dynamic pivot sql that works well, but i still have a simple problem - how to change this line in dynamic part of sql WHERE DUE_DATE BETWEEN DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0) AND DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0,…

Daniel
- 35
- 5