Questions tagged [dynamic-sql]

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.

2681 questions
0
votes
0 answers

Dynamic parameter list with Value in Procedure

I have lot many Stored Procedures that takes 5 to 50 parameters and my client's requirement is to logging each parameters value dynamically while SP is running. Currently we are writing manually code for each SP. I have to create some generic…
Jigar Parekh
  • 595
  • 10
  • 23
0
votes
2 answers

How to count when don't know specific types

I'm working on a table kind of like this: id type 1 A 2 A 3 B 4 C 5 C I wanted to count the number of ids for each type, and get a table like this. type_a type_b type_c 2 1 2 What I did was SELECT SUM(CASE WHEN…
Erin L
  • 95
  • 1
  • 5
0
votes
2 answers

Execute SQL statements in results generated by dynamic SQL statement

I've created a dynamic SQL script to generate statements to replace empty strings with NULL for every column in every table in my database. I've stored the script to the variable @SQL. When I run EXEC @SQL, it generates the following…
0
votes
1 answer

Oracle access the record type values using dot notation with identifiers from varray

I am going to access the values from oracle record using the dot notation and identifier as variable, i am getting error V_COL must be declared. declare cursor c1 is select * from temp_sample_records; type t is table of …
sriman narayana
  • 359
  • 2
  • 20
0
votes
2 answers

SQL Query Timing Issue?

I have a stored procedure that uses a lot of dynamic SQL to process some address data for clients. The first step is that it looks for addresses that are blank and puts them into a table with a [reason] code. The next step looks for addresses that…
Dizzy49
  • 1,360
  • 24
  • 35
0
votes
3 answers

Oracle stored procedure: FOR LOOP over a column from a variable

I want to save a list of column values into the variable input_cols and then loop over the values CREATE OR REPLACE PROCEDURE map_values (mapping_table VARCHAR2(64)) AS TYPE col_names IS TABLE OF VARCHAR2(64); input_cols col_names; BEGIN …
shmail
  • 31
  • 1
  • 5
0
votes
0 answers

Remove leading comma from first column?

I am writing the following dynamic SQL, and getting an error in the PIVOT section of the View creation. Incorrect syntax near ',' FOR [Accounts] IN ( ' + @pivotColumns + ' I know why, its because there shouldn't be a comma that…
Cataster
  • 3,081
  • 5
  • 32
  • 79
0
votes
2 answers

Strip the last dynamic column from ending comma?

I am writing the following dynamic SQL, and getting an error around the FROM keyword. Incorrect syntax near the keyword 'FROM'. ' + @columnList + ' FROM [History] I know why, its because there shouldn't be a comma that precedes it. However,…
Cataster
  • 3,081
  • 5
  • 32
  • 79
0
votes
2 answers

How to use dynamic sql in pl/sql?

I have the following pl/sql procedure as an example (my procedure is much bigger, but my problem is regarding dynamic sql). The problem for me is how to use the variable V_DATE inside SQL_STMT: CREATE OR REPLACE PROCEDURE TEST (DATE_A IN DATE) IS …
Alex C
  • 1
0
votes
1 answer

REGEX using dynamic sql

I have the below regular expression which works perfectly fine using sql, but the same cannot be included in dynamic sql qyery, have tried escaping all the character but it still throws error. here is what I have tried: reg := 'select…
Emma
  • 15
  • 5
0
votes
0 answers

How to save condition to database

I have database. there is table where is column. and column contains conditions > 10, < 10. And I want to build procedure, that will create a select in loop. How I can take condition from table and put it in SELECT * FROM TABLE WHERE @condition@?
0
votes
2 answers

SQL Server dynamic using clause

I've got a really simple dynamic using clause that doesn't work. In fact it causes the script to silently fail and so I'm guessing there is a security issue as SQL Server isn't reporting what is going on and whenever that happens its…
Tom McDonald
  • 1,532
  • 2
  • 18
  • 37
0
votes
2 answers

Implicit conversion - SQL

I have the below SQL query DECLARE @table table(dbname sysname) INSERT INTO @table(dbname) SELECT NAME FROM sys.databases where name like '%AccountsLive' DECLARE @Sql NVARCHAR(MAX) = NULL; SELECT @Sql = COALESCE(@Sql + ' UNION ALL ' + CHAR(13) +…
PeterK
  • 99
  • 6
0
votes
1 answer

Use stored proc parameters in Select dynamic SQL

This question may sound stupid... but hey ! I can't find the answer ! lol!! I have this query that I need to convert to dynamic query: INSERT INTO [SurveyInterface].[tblCEProcessingWorkingLCPSUF]( ParentId, …
MChalut
  • 57
  • 6
0
votes
1 answer

Convert SQL Query to Dynamic SQL

I need to convert my normal SQL query to dynamic sql, can any one please refer the below SQL query and i have posted the error i am facing while executing the dynamic sql SQL Query: insert into p_table_name( select col001, col002, col003, col004,…
1 2 3
99
100