dynamic-sql Questions

3

Solved

I am using dynamic cursor for fetching data. Query that is being executed looks similar to: query := 'SELECT column1, column2 FROM my_table WHERE column1 LIKE ''%:bv1%'''; And the cursor its...
Liverwort asked 22/5, 2017 at 12:48

11

Solved

I'm writing a stored procedure in SQL Server 2008. It's a really long query and I have to write it dynamically, so I create a variable called @Query and make it of type NVARCHAR(MAX). Now, I have b...
Alan asked 28/1, 2011 at 22:8

3

Solved

How can I get the label of each column in a result set to prepend the name if its table? I want this to happen for queries on single tables as well as joins. Example: SELECT first_name, last_na...
Fukien asked 3/3, 2011 at 10:43

11

Solved

I have a piece of dynamic SQL I need to execute, I then need to store the result into a variable. I know I can use sp_executesql but can't find clear examples around about how to do this.
Rotatory asked 29/4, 2009 at 16:33

6

Solved

I have some complex queries to build with a number of optional filters, for which MyBatis seems like an ideal candidate for generating dynamic SQL. However, I still want my query to execute in the...
Angelus asked 2/11, 2012 at 12:21

3

Solved

is possible in PSQL console export file with current date on the end of the file name? The name of the exported file should be like this table_20140710.csv is it possible to do this dynamically? - ...
Magnetograph asked 10/7, 2014 at 7:53

18

Solved

How can I drop all tables whose names begin with a given string? I think this can be done with some dynamic SQL and the INFORMATION_SCHEMA tables.
Uphroe asked 7/8, 2008 at 4:41

6

Solved

So, I've been searching around and I've found things similar to my problem, but I need more help to get a real solution. I'm trying to construct a query that will return 2 columns of data, the fir...
Pinnati asked 16/10, 2009 at 14:43

5

Solved

I am having difficulties writing a Postgres function, as I am not familiar with it. I have multiple tables to import into Postgres with this format: id | 1960 | 1961 | 1962 | 1963 | ... __________...
Ovenbird asked 2/9, 2014 at 14:3

14

Solved

I regularly need to delete all the data from my PostgreSQL database before a rebuild. How would I do this directly in SQL? At the moment I've managed to come up with a SQL statement that returns a...
Mackenie asked 13/5, 2010 at 18:4

3

Solved

I'm regularly re-creating a table in PostgreSQL (9.4.1), much like this: DROP TABLE IF EXISTS test.foo; CREATE TABLE test.foo AS SELECT * FROM test.dagi_kommune WHERE ST_Area(wkb_geometry) < ...
Primrose asked 27/5, 2016 at 14:54

8

Solved

I'm trying to write a stored procedure and depending on a certain column value, I want to be able to change what table I select from. I'll try to give an example: SELECT ItemNumber, ItemType, D...
Corona asked 29/1, 2009 at 17:30

6

Solved

Is it possible via script/tool to generate a delete statement based on the tables fk relations. i.e. I have the table: DelMe(ID) and there are 30 tables with fk references to its ID that I need to...
Tarrasa asked 27/1, 2009 at 22:20

4

Solved

I am trying out some dynamic SQL queries using R and the postgres package to connect to my DB. Unfortunately I get an empty data frame if I execute the following statement: x <- "Mean" query1...
Bust asked 2/4, 2014 at 20:29

4

I keep having this problem: I have like 20 indexes on a table that I need to drop in order to do testing. Dropping the table doesn't drop all of this metadata. There doesn't seem to be a wildcard ...
Showcase asked 1/12, 2015 at 0:10

3

Solved

CREATE OR REPLACE FUNCTION getParentLtree(parent_id bigint, tbl_name varchar) RETURNS ltree AS $BODY$ DECLARE parent_ltree ltree; BEGIN -- This works fine: -- select into parent_ltree l_tree fro...
Hortense asked 26/3, 2014 at 9:33

3

Solved

I am trying to run this function in PostrgeSQL: CREATE OR REPLACE FUNCTION create_partition_and_insert() RETURNS trigger AS $BODY$ DECLARE partition VARCHAR(25); _date text; BEGIN EXECUTE 'SELECT ...
Herculaneum asked 13/10, 2015 at 15:32

4

Solved

I want to build custom Where condition based on stored procedure inputs, if not null then I will use them in the statement, else I will not use them. if @Vendor_Name is not null begin set @whe...
Galengalena asked 30/9, 2013 at 9:33

12

Solved

How do I write an SQL script to create a ROLE in PostgreSQL 9.1, but without raising an error if it already exists? The current script simply has: CREATE ROLE my_user LOGIN PASSWORD 'my_password'...
Swihart asked 11/11, 2011 at 9:39

3

This is a follow on question to Vincent Malgrat's answer to this question. I can't find the correct syntax to use when you need to use the same bind variable multiple times when using OPEN...FOR dy...
Olethea asked 4/3, 2020 at 16:23

3

Solved

As part of some administrative tasks, we have many tables that each need a trigger created. The trigger will set a flag and the date in the Audit database when an object has been modified. For simp...
Negative asked 26/4, 2012 at 15:18

4

Solved

How do I update different columns and rows across a table? I want to do something similiar to replace a string in SQL server I want to do this but the value exists in multiple columns of the same ...
Vercingetorix asked 23/7, 2009 at 1:8

2

Solved

I have an SQL script that needs to drop several constraints and restore them at the end, but the constraint names are auto-generated and will be different each time the script is run. I know how t...
Edeline asked 12/9, 2012 at 20:3

5

Solved

I have a sql function that does a simple sql select statement: CREATE OR REPLACE FUNCTION getStuff(param character varying) RETURNS SETOF stuff AS $BODY$ select * from stuff where col = $1 $BO...
Nicholnichola asked 15/11, 2011 at 16:25

9

[Update: Using SQL Server 2005] Hi, what I want to do is query my stored procedure with a comma-delimited list of values (ids) to retrieve rows of data. The problem I am receiving is a conversio...
Impolitic asked 5/2, 2009 at 17:54

© 2022 - 2024 — McMap. All rights reserved.