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

How to run dynamic query depending on selected options in android?

Suppose I have the following table in a mysql database of my app: TABLE MANAGER Now I want to add this checkbox option in android. And based on the selections I would want to run query in my database. For example if the user selected NY and NJ,…
user4057131
0
votes
1 answer

Update table using nested cursors in SQL Server

Kindly help me to optimize this code, or let me know if I can do this in a better way. Req: I'm updating Product table which will have product info. The idea is to fetch some columns from other tables through join. (curTaxonomy is doing that.) And…
MD SARFARAZ
  • 117
  • 3
  • 17
0
votes
3 answers

Adding Quoted Datetimes from Paramaters in Dynamic SQL String for sp_executesql

I am currently working on an SQL Server 2005, and trying to structure a dynamic query as follows: DECLARE @GETDATE AS NVARCHAR(12); DECLARE @GETDATE2 AS NVARCHAR(12); SET @GETDATE = ...; SET @GETDATE2 = ...; SET @SQL = 'CREATE TABLE [dbo].['…
3BK
  • 1,338
  • 1
  • 8
  • 11
0
votes
1 answer

How to execute a SQL query using Entity Framework that returns Anonymous ResultSet using DBContext

How can I execute a raw SQL query which returns an anonymous type? I also followed msdn link, but I couldn't find any solution for using DbContext. Thanks in advance. I resolved the issue. First I converted my DbContext Object to ObjectContext…
0
votes
0 answers

Conditional Where Vs Dynamic query

Most of us have used conditional where clause in our queries to get desired output for multiple parameter WHERE (@Variable1 IS NULL OR Column1 = @Variable1) AND (@Variable2 IS NULL OR Column2 = @Variable2) AND (@Variable3 IS NULL OR Column3 =…
Kai
  • 352
  • 1
  • 16
0
votes
1 answer

SQL Server 2008 R2: Dynamic pivot query

I have the table called as sales with three columns SalesCountry , SalesState and SalesMan as shown below: Table: create table sales ( SalesCountry varchar(20), SalesState varchar(20), SalesMan varchar(20) ); Insertion: insert into…
MAK
  • 6,824
  • 25
  • 74
  • 131
0
votes
1 answer

SQL Invalid Column error on Dynamic Query

I have the following query: DECLARE @DynamicPivotQuery AS NVARCHAR(MAX) DECLARE @ColumnName AS NVARCHAR(MAX) SELECT @ColumnName = ISNULL(@ColumnName + ',','') + QUOTENAME(MaxDate) FROM (SELECT DISTINCT MaxDate FROM CustPeriodTable) AS MaxDates SET…
user41829
  • 95
  • 1
  • 1
  • 10
0
votes
1 answer

Group by or aggregate error even though field is included in group by list

I have an SQL multiple value grouping query in which I want to find the maximum of the field slt.OUTCOST. Running it results in the following error: Column '#eldekiSeri.CODE' is invalid in the select list because it is not contained in either an…
0
votes
2 answers

WITH statement in dynamic sql

I need to store a query as a stored procedure in SQL Server. I need also to pass parameters which define tablenames and column names. This is the query I owuld like to have, I tried to store it in a string and then EXECUTE it but without success, ho…
frx08
  • 4,222
  • 8
  • 37
  • 45
0
votes
1 answer

MySQLi prepared statement executes twice on insert

I usually don't post detailed versions of my code; however, in this case it may be necessary to figure out the problem. I have a class method that I cannot stop from executing twice. Is there any particular information I am missing on MySQLi…
0
votes
0 answers

dynamic query with date criteria

I am trying to implement search query using dynamic query I created dynamic query like this DynamicQuery dynamicQuery=DynamicQueryFactoryUtil.forClass(OrderSubscription.class,PortletClassLoaderUtil.getClassLoader()); DynamicQuery…
Ravi Darji
  • 11
  • 5
0
votes
2 answers

MSSQL Dynamic SQL query ISNULL

I have a problem in my dynamic query I want that the values that are null to convert in zero, I found the function that convert but in my dynamic query does not work SET @DynamicPivotQuery = 'select * from ( select ct.category as [name], …
Dan Paschevici
  • 961
  • 2
  • 10
  • 22
0
votes
1 answer

Dynamic query in configuration table - must declare the scalar variable

I have the following code: /* Log Table */ IF OBJECT_ID('tempdb..#LogETL') IS NOT NULL DROP TABLE #LogETL CREATE TABLE #LogETL ( LogETL INT IDENTITY(1,1) NOT NULL, StartTime DATETIME, EndTime DATETIME, JobName VARCHAR(100), StepName…
DNac
  • 2,663
  • 8
  • 31
  • 54
0
votes
1 answer

Linq Dynamic OR condition

I am having a User Table like this, Id(int) Name(string), State_Id(Int64), Country_Id(Int64), MobileNumber(String), email(String), identity(String) Role_Id Disable(Boolean) Identity column will have values comma separated for example(,mole in hand,…
0
votes
0 answers

why does not a placeholder inside a method in insert sql work?

In my case, INSERT INTO xmltable (id, xml_content) VALUES (?,XMLPARSE(DOCUMENT 'abcxyz' PRESERVE WHITESPACE)) is working fine, but INSERT INTO xmltable (id, xml_content)…