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
2
votes
0 answers

Postgresql function: How to handle empty value in [ IN() or ANY() ]

I have a Postgresql function with dynamic query. In that query i have to pass a list into the IN() or ANY() as argument. It works fine when it have value in the passing list. But when the list is empty it is throwing an error. Query: query :=…
Akbar Badhusha
  • 2,415
  • 18
  • 30
2
votes
2 answers

Dynamic query to select column based on the condition

Is it possible to select column based on the condition for dynamic queries. If condition is false, then it should not select that column. I want to write below as a dynamic query. DECLARE @param varchar(10), SELECT A, IF (@param = 'U') B = A-2,…
S M
  • 159
  • 2
  • 13
2
votes
2 answers

Dynamic SQL - How to use a value from a result as a column name?

I am working on a dynamic SQL query for a MsSQL stored procedure. There is a table search.ProfileFields that contains the actual column names in a table I need to query. My goal is to have the SQL select the specific column in the table,…
SBB
  • 8,560
  • 30
  • 108
  • 223
2
votes
2 answers

Mybatis dynamic column in select statement

I'm trying to select dynamic column. Below are my codes: //call the dao method String columns = "first_name"; userDao.sample(1, columns); //call mapper List sample(@Param("userId") int userId, @Param("columns") String…
Chong We Tan
  • 233
  • 5
  • 15
2
votes
1 answer

Dynamic Query in OpenEdge

Good day: Quick question: Can I perform a dynamic query in OpenEdge? Example: def temp-table tt-num1 field f1 as int field f2 as int. def temp-table tt-num2 field f1 as int field f2 as int. def temp-table tt-num3 field f1 as int field f2 as…
noob
  • 165
  • 3
  • 18
2
votes
1 answer

Output the result of a SELECT executed using dynamic PL/SQL

Using T-SQL (SQL Server) this couldn't be easier: DECLARE @MyStatement AS NVARCHAR(max) = 'SELECT * FROM MYTABLE' EXEC (@MyStatement) However, using PL/SQL (Oracle) it's been a real pain in the ass. After a couple of hours I could finally reach…
Luis Gouveia
  • 8,334
  • 9
  • 46
  • 68
2
votes
1 answer

How do I escape a single quote in dynamic SQL

I have the following query on SQL Server, some of the values are stored in variables computed earlier: SET @Command = N'INSERT INTO Products (Id ,Region ,Name …
Cranialsurge
  • 85
  • 1
  • 6
2
votes
2 answers

Incorrect Syntax Near GO, T-SQL EXEC()

I am using the following script: DECLARE @dbName NVARCHAR(20) = 'ABC'; EXEC ( N' USE ' + @dbName + ' GO -- Create Schema CREATE SCHEMA meta GO -- Create Log Table CREATE TABLE meta.LogAudit( [EventDate] [datetime] NOT NULL DEFAULT…
DNac
  • 2,663
  • 8
  • 31
  • 54
2
votes
3 answers

Oracle: update multiple columns with dynamic query

I am trying to update all the columns of type NVARCHAR2 to some random string in my database. I iterated through all the columns in the database of type nvarchar2 and executed an update statement for each column. for i in ( select …
rav
  • 247
  • 1
  • 6
  • 17
2
votes
1 answer

DynamicQuery parent-child error java.sql.exception Operand should contain one column(s)

I'm trying to code the following query: select * from mySchema.journalArticle parent where parent.structureId in (?) and parent.companyId = ? and parent.groupId = ? and parent.status = ? and parent.version in…
2
votes
1 answer

best way to support dynamic column name and sort direction with peewee python

So far i have something like this: page_nr = request.query.page_nr how_many = request.query.how_many sort_direction = request.query.sort_direction sort_column = request.query.sort_column error_urls = Url.select().where((Url.crawl == crawl_id)) \ …
Dan
  • 2,209
  • 3
  • 23
  • 44
2
votes
1 answer

Dynamic charting in Netlogo

In my model, the number of turtle is dynamic based on the value defined by the user using a slider. The slider can take values between 2 and 10. Each turtle has its own set of co-ordinates and characteristics, hence i used the following code to…
Raj
  • 1,049
  • 3
  • 16
  • 30
2
votes
1 answer

Remove objects from query if None or Null

I am trying to build a query that takes form data and removes any None or " " submissions but I'm not sure how to approach the logic. Here is the code; @app.route('/filterassets', methods=['GET', 'POST']) def searchassets(): form =…
2
votes
1 answer

Substitute Column name in dynamic queries

I have a procedure , in which i am receiving a parameter column name and creating the dynamic query by substituting column name. when i am directly running this dynamic query its working fine. declare @a datetime, @b varchar(50)…
gkarya42
  • 429
  • 6
  • 22
2
votes
2 answers

Can I chain a variable number of query scopes using Laravel 5

My users need to be able to query the database with up 5 different parameters. I think the best way to handle this is with query scopes. Then just chain together the query scopes. But I cannot figure out how to do this based on an unknown number…
Brent Connor
  • 628
  • 2
  • 8
  • 23
1 2
3
22 23