dynamic-sql Questions

2

Solved

I implemented this function in my Postgres database: http://www.cureffi.org/2013/03/19/automatically-creating-pivot-table-column-names-in-postgresql/ Here's the function: create or replace functi...
Histaminase asked 22/4, 2016 at 22:57

1

Solved

--sp_executesql version --SET @SQLQUERY = 'UPDATE @TableName SET Brief = @Brief, -- [Full] = @Full, -- CreatedBy = @CreatedBy, -- Department = @Department, -- Answer = @Answer WHERE Id=@Id'; ...
Metritis asked 16/4, 2016 at 6:20

1

Solved

I have a project where the front-end JavaScript specifies a list of columns to order by. Then in the back-end I have multi-layer application. Typical scenario Service layer (the service models' ...

5

Solved

I have a query where not all conditions are necessary. Here's an example of what it looks like when all conditions are used: select num from (select distinct q.num from cqqv q where q.bcode = '1...
Elbring asked 11/11, 2009 at 16:58

1

Solved

I tried to use a function to set the n_distinct value for a table. The code is as follows: create temporary table _temp ( id integer ); create function pg_temp.setdistinct(_cnt real) returns voi...
Fuqua asked 16/3, 2016 at 1:34

2

Solved

I'm not sure how to achieve something like the following: CREATE OR REPLACE FUNCTION fnJobQueueBEFORE() RETURNS trigger AS $$ DECLARE shadowname varchar := TG_TABLE_NAME || 'shadow'; BEGIN INS...
Unrivalled asked 27/10, 2011 at 9:57

4

Solved

I have a complex SQL query that can be simplified to the below: Select ColA,ColB,ColC,ColD From MyTable Where (ColA In (Select ItemID From Items Where ItemName like '%xxx%') or ColB In (Select I...
Deflagrate asked 29/2, 2016 at 8:46

1

Solved

I'm new to plpgsql. I'm trying to run a simple query in plpgsql using a variable as table name in plpgsql. But the variable is being interpreted as the table name instead of the value of the variab...
Arabian asked 22/2, 2016 at 16:43

3

Solved

This static query using a parameter returns one row: DECLARE @sqltext nvarchar(max) DECLARE @status varchar(100) SET @status = 'Active: Complete' select * from status where StatusTitle = @status ...
Interbedded asked 3/2, 2016 at 6:58

1

I have a SELECT query on a view, that contains 500.000+ rows. Let's keep it simple: SELECT * FROM dbo.Document WHERE MemberID = 578310 The query runs fast, ~0s Let's rewrite it to work with the...
Euxenite asked 26/1, 2016 at 9:21

4

Solved

I have a query where I'm trying pivot row values into column names and currently I'm using SUM(Case...) As 'ColumnName' statements, like so: SELECT SKU1, SUM(Case When Sku2=157 Then Quantity Else ...
Polyhymnia asked 31/3, 2010 at 16:48

2

Solved

I have a table with a long text column. I'd like to be able to select all of the columns but limit the text column without needing to write every column. select * from resources; Produces an out...
Kinescope asked 23/11, 2015 at 16:0

1

With reference solution I've posted in my previous post resulted in one more situation. While trying to insert into my destination table(schema as below). -- Table: normalized_transaction -- DROP...
Confectioner asked 9/12, 2015 at 6:22

2

Solved

Raw Table for which rule are stored in one table named md_formula , which are used to map in destination table Drop/Create/Insert for raw_dbs_transactiondetailscash: DROP TABLE raw_dbs_transactio...
Diplodocus asked 7/12, 2015 at 12:10

2

Solved

I'm trying to create a dynamic database creation script. There are a lot of steps and we create this database often so the script looks something like this. DECLARE @databaseName nvarchar(100) =...
Saccharify asked 16/1, 2014 at 21:35

5

Solved

I want to write a simple query to select a number of columns in PostgreSQL. However, I keep getting errors - I tried a few options but they did not work for me. At the moment I am getting the follo...
Glume asked 4/4, 2013 at 0:6

4

Solved

I'm trying to create a script to migrate data from one DB to another. One thing I'm not currently able to do is set the nextval of a sequence to the nextval of a sequence in another DB. I got the ...
Excretion asked 30/4, 2012 at 11:40

3

Solved

I have a huge schema, with several hundreds of tables and several thousands of columns. I'd know that a specific IP address is stored in this database in several places, but I'm not sure what table...
Aylward asked 10/10, 2012 at 16:58

1

Solved

In SQL Server 2014, I am trying to create a dynamic WHERE clause. I have built the query as a string, but when I try to execute it with sp_executesql, I get the following error: Líne 13 You must ...
Rizzio asked 11/9, 2015 at 5:32

2

Solved

I am facing some problem with making a SQL insert statement dynamically from a dataTable object in c#. I want to know the best practices to make it.Here is my code snippet , I have tried so far. ...
Grate asked 18/2, 2014 at 14:54

3

Solved

I support a SQL database for a third party software package. They have a lot of what they call "Shadow Tables", really just audit tables. This is all fine and good but their system does not clean u...
Berar asked 25/8, 2015 at 17:17

1

Solved

I'm trying to Partition a Table by both Year and Month. The Column through which I'll partition is a datetime type column with an ISO Format ('20150110', 20150202', etc). For example, I have sale...
Rialto asked 10/8, 2015 at 15:55

1

Solved

This thread is a part challenge of this thread to which I am searching a better solution for one part by BEFORE TRIGGER. I just want to launch a trigger to convert to correct brackets. I am think...
Middaugh asked 2/8, 2015 at 16:44

2

Solved

I have this function in PostgreSQL: CREATE OR REPLACE FUNCTION func1(a integer, b timestamp, c integer[]) RETURNS SETOF typ_new AS $BODY$ declare begin CREATE OR REPLACE VIEW newView as (select...
Stockman asked 29/6, 2015 at 7:40

3

Solved

I want to execute a dynamic SQL statement, with its returned value being the conditional for an IF statement: IF EXECUTE 'EXISTS (SELECT 1 FROM mytable)' THEN This generates the error ERROR: typ...
Aurelio asked 9/12, 2011 at 17:1

© 2022 - 2024 — McMap. All rights reserved.