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
-1
votes
1 answer

Syntax error when trying execute dynamic query which contain dollar quoting to escape nested single quotes

I have following piece of code, which does following Generate set of string column names when provided a date range which are simply dates between the range Then this function is used within an another function to generate dynamic query string Next…
user158
  • 12,852
  • 7
  • 62
  • 94
-1
votes
1 answer

Can a SELECT statement use variables containing field names?

I'm using SQL Server 2008R2 with SSMS17 and am trying to automate some 'least used fields' reports based on current data. Ideally, I'd like to retrieve the list of these fields into a table variable, then create a SELECT statement where I pull the…
MJA
  • 350
  • 1
  • 3
  • 15
-1
votes
1 answer

Dynamic group by in a MySql query

I have an employees table which has fields like Name, Salary, City, Country, Department. I also have a user input where user can select multiple column headers e.g. City, Country etc. from my employees table. I need to make a dynamic query that…
Ujjwal Vaish
  • 373
  • 1
  • 7
  • 21
-1
votes
1 answer

How to provide dynamic table name with Date Time in query of SQL Server

I have to take backup of a table in SQL Server, but I don't want to give specific name to the particular backup table, because in a day there could be n number of backup of that particular table because of this reason, I have to change the name of…
MayankGaur
  • 957
  • 11
  • 22
-1
votes
1 answer

SQL Server stored procedure dynamic query (openquery) for a linked SQLite database returns errors

I have SQL Server 2019 and have linked an SQLite database called [PSMDB_WIN_SVR] to it. My objective is to retrieve data from the linked database for all records greater than or equal to a double variable parameter representing Julian Date/Time. The…
-1
votes
1 answer

Pivot table not worked by dynamic parameter

I wrote this query: declare @startdate nvarchar(10) = '2016/01/01', @enddate nvarchar(10) = '2019/10/04', @cols nvarchar(max), @strsql nvarchar(max); select @cols = (select distinct QUOTENAME(maintenancename)+',' …
Mehrdad
  • 39
  • 5
-1
votes
1 answer

Unable to Run Query, dbo.tablename invalid object name?

I am trying to build a dynamic query that will insert or update a record based on row exists in db, if yes i will update a bunch of records & sub records depending on @ObjectID. Here is my query: DECLARE @ObjectID BIGINT = 0; SET @ObjectID = 0; IF…
Alok
  • 808
  • 13
  • 40
-1
votes
1 answer

Dynamic bind select values in MySQL query jdbi

How can i write dynamic SQL query in Jbdi, like in my project customer will ask some details like first name,last name,mobile. so i will read those values into string and my idea was directly append that to SQL query dynamically like select first…
Nike
  • 5
  • 6
-2
votes
1 answer

Multiple dynamic query in Linq

First of all, I will explain the table structure First table Attribute Second table Category Id Name Id Name AttributeId(Foreign Key) ------------------ ----------------------------------------- 1 Material…
Nighil
  • 4,099
  • 7
  • 30
  • 56
-2
votes
1 answer

Spring Boot JPA with Dynamic Table and column

How to run SQL query in spring boot when my tables' name is dynamic and the number of the columns of the table is also dynamic/varying depending on the requirement. While using entity class we require to set static table and column names. Eg-…
-2
votes
1 answer

While LOOP IN Dynamic QUERY

BEGIN DECLARE @sqlQuery VARCHAR(MAX) SET @sqlQuery ='Select Style_Color, Style_Color_Desc as Description, RPT, Weeks, ' DECLARE @cnt INT = 1 DECLARE @TblCount NVARCHAR(1000) = (SELECT COUNT(ID) FROM table_Name) WHILE @cnt <=…
sravas
  • 41
  • 8
-2
votes
1 answer

How to create dynamic sql inline statement?

I am creating advance search facility in one of my application. In that functionality i have to store selected search criteria. My search result is based on Logi XML...Logi XML requires SQL inline statement so that reason i have to store sql inline…
user968441
  • 1,471
  • 9
  • 22
  • 48
-3
votes
1 answer

Execute Dynamic query inside Select query in stored procedure SQL Server

I am trying to execute dynamic generated select query as a column value of Select statement. I tried using functions but that don't allow to execute dynamic query block. Can anyone have way around to get me the desired solution? create table…
Akshay
  • 77
  • 1
  • 1
  • 6
-3
votes
2 answers

How to fix "Must declare the scalar variable" issue in sql server dynamic query?

I am trying to execute this statement in sql server: EXECUTE ('SELECT @lnRowIdMin = MIN(TMP_ROW_ID) FROM #' + @lvcBaseTable). Here @lnRowIdMin is declared as an integer variable and @lvcBaseTable is declared as an varchar(255) variable in my…
user11668855
  • 3
  • 1
  • 1
  • 2
1 2 3
22
23