Questions tagged [dynamicquery]

Use this tag for questions related to dynamic queries; queries that are built dynamically rather than provided as an explicit query string.

is usually found in questions related to SQL, C#, Drupal, Java, etc., so if you are about to use this, make sure you accompany it by the corresponding tag of your programming environment.

344 questions
0
votes
1 answer

Missing Column(s) in MySQL Crosstab Query

So I have a very complicated crosstab query for my client, who manages student aid for various colleges. The query is dynamic, so it's built as a long string in the stored procedure, then prepared, executed and deallocated. I've been able to extract…
RMittelman
  • 319
  • 3
  • 16
0
votes
3 answers

Dynamically Query All SQL Tables Matching Certain Criteria

I have a SQL Server database with dozens of tables that contain HTML content. I need to query these tables to see if they contain a particular email address within their content fields. I am able to identify the tables and columns that need to be…
Tom Faltesek
  • 2,768
  • 1
  • 19
  • 30
0
votes
1 answer

Put variable tablename in cursor statement

Can someone help me how to write a dynamic query in PL/SQL, and define the table name as a variable in the dynamic query (in other words I need to write a dynamic query which accept table name as a variable)? I think it could be done by cursor, but…
0
votes
0 answers

trying to generate deep complex sql queries dynamically

I am trying to construct a Dynamic SQL query using multiple filter conditions (where clause) which can get complex and deeper with sub-queries and joins. I have already build a basic structure for this using FilterClass { Column, Operator, …
0
votes
1 answer

How to use CTE with dynamic query pivot?

I am using SQL Server 2008 R2 First I needed to break the dates (start date and end date) into every day from table1 which I did with recursive CTE. DECLARE @maxdate DATETIME = (SELECT Max([EndDate]) FROM table1); WITH CTE_DateToDays AS…
0
votes
2 answers

Is there an easy way to calculate 12 months moving average in PostgreSQL?

This very simple SQL can calculate averages, medians etc. for a well defined periods, like year, month, quarter, week, day: SELECT date_trunc('year', t.time2), -- or hour, day, week, month, year count(1), percentile_cont(0.25) within group…
edaus
  • 179
  • 1
  • 1
  • 11
0
votes
1 answer

passing function parameters to dynamic query string

I'm using PostGreSQL 11.4, just started to play with dynamic queries and I'm missing something. I want to use a function parameter inside the query and I'm doing it wrong. this is what I have: create or replace function…
ufk
  • 30,912
  • 70
  • 235
  • 386
0
votes
1 answer

Oracle - Create a view with data from different table as column names

Create view with fields from another table as column headers I've got two tables that I'd like to combine into a view. The first table contains the structure: PhoneNumberType PhoneNumberTypeName 101 Mobile 102 …
0
votes
0 answers

How to execute a dynamic query in BigQuery?

I have the following query: WITH modalities as ( SELECT DISTINCT col4 as modalities FROM `myproject.table1` SELECT CONCAT(""" SELECT col1,col2, col3 """, STRING_AGG( if_clauses , """, """), …
Théophile Pace
  • 826
  • 5
  • 14
0
votes
1 answer

Have Stored Proc with Dynamic SQL that creates loads of results tabs

I have built an SP with Dynamic query code. Trouble is that every time it does something it sends something to a new results tab. Below is a cut down version of the code. CREATE PROCEDURE p() BEGIN DECLARE x,z INT; SET x = 0; SET z =…
Andrew Whittam
  • 49
  • 1
  • 1
  • 6
0
votes
0 answers

How do I add a column to a select, from a stored procedure depending on the results from the query?

I am using Oracle SQL Developer and I need do a search in a table to find if at lest one record matches. After the search is done, a value of true or false is returned from the stored procedure. I was asked to not only return that result of true or…
0
votes
2 answers

How to write a recursive query with 2 tables in SQL Server

I have a table with the following structure. Table name: Table0 The structure is as below Select process from Table0 where Name like '%Aswini%' Process ------- 112 778 756 All these process must go into the below table Table name: Table1 The…
0
votes
2 answers

Eloquent, how to get calculated sum of fields in a new field

I have a DB table students with all the subjects final grades for each subject what is quite a number, and a number of other fields, like name, etc. students (table is having more than 100 columns, each cell can have some pre-set ID, which later…
Alexey Abraham
  • 379
  • 2
  • 13
0
votes
0 answers

Entity Framework 6 Custom SqlQuery returns null object

I want to run a dynamic custom query which is not bound to any object or class in my project. It will always return null or 1 record. I tried many things but without success so far: // this is working function with hard-coded query private…
user10182659
0
votes
2 answers

SQL Transformation Dynamic Query Generation Limitation

I'm using an expression transformation to dynamically generate a query which serves as the input to my SQL transformation. Since the query is already generated in the expression, i'm using String substitution. Issue: My generated query is more than…
rcmaiden
  • 51
  • 1
  • 4