dynamic-sql Questions

21

Solved

Why would someone use WHERE 1=1 AND <conditions> in a SQL clause (Either SQL obtained through concatenated strings, either view definition) I've seen somewhere that this would be used to pro...
Stairwell asked 28/10, 2008 at 10:37

9

Solved

The code is as follows: ALTER PROCEDURE dbo.pdpd_DynamicCall @SQLString varchar(4096) = null AS Begin create TABLE #T1 ( column_1 varchar(10) , column_2 varchar(100) ) insert into #T1 ex...
Machmeter asked 19/3, 2009 at 12:35

1

Solved

Should we rather use the concatenation operator || or the format() function in trigger functions? Is there any advantage of using one over the other or does it come down to personal preference and ...
Tracey asked 9/3, 2021 at 21:46

7

Solved

I am writing a stored procedure, which opens a cursor to a table, and then iterate through all records. In the iterating process I create a dynamic query based on the results of the first cursor. I...
Fredelia asked 21/5, 2011 at 14:11

11

Solved

Get the above error when the execute immediate is called in a loop Update CustomersPriceGroups set 1AO00=:disc Where cuno=:cuno Parameters: disc=66 cuno=000974 Update CustomersPriceGroups set 1AP...
Cerulean asked 27/2, 2012 at 2:2

16

Solved

I've spent a good amount of time coming up with solution to this problem, so in the spirit of this post, I'm posting it here, since I think it might be useful to others. If anyone has a better sc...
Into asked 22/8, 2008 at 0:58

1

Solved

I would like to select all sequences in the database, get the schema of sequence, dependent table, the schema of a table, dependent column. I've tried the following query: SELECT ns.nspname AS s...
Valerlan asked 21/7, 2020 at 20:15

8

Solved

I want to pass a table name as a parameter in a Postgres function. I tried this code: CREATE OR REPLACE FUNCTION some_f(param character varying) RETURNS integer AS $$ BEGIN IF EXISTS (select * ...
Fetishism asked 22/5, 2012 at 15:55

1

Is it possible to filter on column names themselves in psql? I want to generate a limited version of the original table (with several hundred columns) in a separate schema a la (pseudocode): crea...
Avigation asked 18/4, 2020 at 19:25

4

Solved

I wrote a function that outputs a PostgreSQL SELECT query well formed in text form. Now I don't want to output a text anymore, but actually run the generated SELECT statement against the database a...
Ting asked 31/7, 2012 at 12:38

3

Solved

Why do I get this error Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'. when I try to use sp_executesql?
Demilitarize asked 30/4, 2010 at 10:41

2

Solved

I want to create a script that will have variables of _user and _pass to create the user in the Postgres database only if such login does not exist yet. I was thinking this would work, but i cant t...
Unalloyed asked 8/3, 2018 at 9:26

2

Solved

Which are the differences between DBMS_UTILITY.EXEC_DDL_STATEMENT and EXECUTE IMMEDIATE?
Antitype asked 7/8, 2011 at 13:1

2

Solved

Following the approach mentioned in this link, I want to pass ORDER BY and sorting order to a function dynamically. ORDER BY is working fine but I am not able to pass sorting order (ASC / DESC). Wh...
Haircloth asked 11/4, 2018 at 12:31

7

Solved

I keep all my functions in a text file with 'CREATE OR REPLACE FUNCTION somefunction'. So if I add or change some function I just feed the file to psql. Now if I add or remove parameters to an exis...
Decasyllabic asked 1/10, 2011 at 20:54

7

Solved

I have a dynamic SQL statement I've created in a stored procedure. I need to iterate over the results using a cursor. I'm having a hard time figuring out the right syntax. Here's what I'm doing. S...
Overnice asked 25/6, 2009 at 19:51

5

Solved

I have a PostgreSQL function (or table) which gives me the following output: Sl.no username Designation salary etc.. 1 A XYZ 10000 ... 2 B RTS 50000 ... 3 C QWE 20000 ... 4 D HGD 34343 ... N...
Inae asked 29/12, 2012 at 18:7

7

I'm trying to dynamically create triggers, but ran into a confusing issue around using sp_executesql and passing parameters into the dynamic SQL. The following simple test case works: DECLARE @tab...
Nambypamby asked 30/1, 2019 at 17:56

4

Solved

I am trying to create crosstab queries in PostgreSQL such that it automatically generates the crosstab columns instead of hardcoding it. I have written a function that dynamically generates the col...
Freeliving asked 14/10, 2012 at 5:56

2

Solved

I have a variable which has SQL string stored in it and am executing it through exec() Declare @sql varchar(max) set @sql = Concat('select...',@var,'..') -- large string exec (@sql) but am ge...
Karalynn asked 2/11, 2016 at 10:2

5

Solved

I was attempting to use Dynamic SQL to run some queries in postgres. Example: EXECUTE format('SELECT * from result_%s_table', quote_ident((select id from ids where condition = some_condition))) ...
Cheerless asked 8/10, 2012 at 10:54

4

Solved

I have the following dynamic query which is working fine without the WHERE clause, which is expecting UNIQUEIDENTIFIER. When I pass it in, I don't get a result. I tried CAST and CONVERT, but no r...
Tussock asked 24/6, 2009 at 6:46

3

I'm trying to create a generic SQL include in Mybatis that will apply a comparator given a particular value. The idea is to reuse this sql code snippet across several mappers. The issue I'm having ...
Porta asked 8/2, 2016 at 5:30

5

Solved

We've just been given the following code as a solution for a complicated search query in a new application provided by offshore developers. I'm skeptical of the use of dynamic SQL because I could c...
Disincline asked 6/11, 2008 at 10:10

1

I have to consolidate data from from 1000+ databases having the same structure/tables in one unique DB. DBs may be added and removed potentially on a daily basis so I need to retrieve the list of D...
Jodhpur asked 30/1, 2018 at 15:38

© 2022 - 2024 — McMap. All rights reserved.