dynamic-queries

How to preserve the order of the fields to be selected when using $query->addExpression()

本秂侑毒 提交于 2019-12-11 04:08:33
问题 I'm using Drupal 7 and I have to make a union on multiple tables. For the union to work some conditions have to be met: same number of columns same data type same order Some of the tables are missing a column so in order to compensate for that I just add it with something like this: $query->addExpression(':field_1', 'field_1', array(':field_1' => NULL)); . So at this point condition 1 & 2 are satisfied, but the order of the fields in the select is different. See example bellow: $query_1 = db

LINQ - dynamic orderby clause does not work

守給你的承諾、 提交于 2019-12-10 14:16:55
问题 I have code like this: //build query var shops = (from p in dataContext.shops let distance = dataContext.GetDistance(p.lat, p.lon, nearlat,nearlon) join c in dataContext.shops_category on p.id equals c.poi_id select new ShopsModel { p = p, distance = distance } ); } //add dynamic orderby if(somthig) shops.OrderBy(distance) else shops.OrderBy(p.name) //get records. return shop.Take(30).ToList() It's works fine except OrderBy. Generated SQL code does not contains orderby clause and the records

add column dynamically with select query

╄→гoц情女王★ 提交于 2019-12-08 06:24:25
问题 I have one table which has 20 columns default These 20 columns named as D1 D2 D3...D20 , now with select query i want to add the other columns dynamically.. for ex D21 D22...D31, so how can i write a query to add this columns dynamically with incremented value..max limit is 31,please help default table columns D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 D14 D15 D16 D17 D18 D19 D20 now i want to add columns in continuity to D20 i.e D21 and so on upto D31 , while selecting this columns the other

how to pass variables this in dynamic query in sql

纵饮孤独 提交于 2019-12-02 06:08:35
i using the dynamic query to pass the variables select a.TableName, COUNT(a.columnvalue) as '+'count'+' from Settings a where a.ColumnValue in ('+ @columnvalue +') and a.Value in (' + @value +') the @columnvalues = 'a','b','c' @value ='comm(,)','con(:)' how to pass this in dynamic query any idea??? Jim B I would use the sp_executesql command. Some more documentation is here: http://msdn.microsoft.com/en-us/library/ms188001.aspx Basically, you define a sql query, and parameter list, and then pass those in along with your actual parameters into that method. So, something like this (real basic)

Assign function result to a table variable

。_饼干妹妹 提交于 2019-12-01 09:19:50
问题 The SQL Server (2000/2005) function gets the table name and the field name as parameters and returns results from a dynamic query within the function. The results should be assigned to a Table variable which will be used further in a stored procedure. How to achieve this? I am getting error: "Only functions and extended stored procedures can be executed from within a function." Declare @Data as table (FieldValue varchar(100)) insert into @Data select * from MyFunction ('Person.Address',

Creating an expression from the string of a property name?

ぐ巨炮叔叔 提交于 2019-12-01 01:29:53
I am trying to create a query based on some JSON, I currently have the JSON parsed into a set of rules, each rule contains the name of the field, the type of comparison (=, > etc) and the value to compare. The issue I am having is getting it from that rule, to an IQueryable object, I am guessing I need to use reflection and somehow build the expression tree, but I'm not sure on the right approach... Assuming I have: public class Order : BaseEntity { public int OrderID{ get; set; } } and I have the rule which is: public class Rule { public string field { get; set; } public Operations op { get;

Creating an expression from the string of a property name?

笑着哭i 提交于 2019-11-30 19:53:30
问题 I am trying to create a query based on some JSON, I currently have the JSON parsed into a set of rules, each rule contains the name of the field, the type of comparison (=, > etc) and the value to compare. The issue I am having is getting it from that rule, to an IQueryable object, I am guessing I need to use reflection and somehow build the expression tree, but I'm not sure on the right approach... Assuming I have: public class Order : BaseEntity { public int OrderID{ get; set; } } and I

Spring Data MongoDB Repository - JPA Specifications like

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:30:57
Is there something like JPA Specifications for Spring Data MongoDB Repositories? If not, how can I make dynamic queries with repositories? A classic scenario could be a search form with optional fields that the user will fill. I found myself a way. The trick can be done using QueryDSL , in the following way: First, add the QueryDSL dependencies: <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-mongodb</artifactId> <version>${querydsl-mongo.version}</version> </dependency> <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>

My SQL Dynamic query execute and get ouput into a variable in stored procedure

梦想的初衷 提交于 2019-11-27 08:08:40
I generate a dynamic query in My sql Stored procedure. I wanna get the result of this query into a out parameter. How to do this ? CREATE PROCEDURE 'searchInvoice' ( OUT numOfRecords INT ) BEGIN DECLARE query1 TEXT; DECLARE query2 TEXT; SET query1 = 'SELECT COUNT(*) bla bla bla.....'; // Query1 to select the count of matching tuples.. SET query2 = 'SELECT * from bla bla bla....'; // Query2 to select original records... // later part of this both queries generate dynamically according to some IN parameters.. // now I wanna assign the output of the query1 into numOfRecords // and I wanna execute

My SQL Dynamic query execute and get ouput into a variable in stored procedure

允我心安 提交于 2019-11-26 17:44:58
问题 I generate a dynamic query in My sql Stored procedure. I wanna get the result of this query into a out parameter. How to do this ? CREATE PROCEDURE 'searchInvoice' ( OUT numOfRecords INT ) BEGIN DECLARE query1 TEXT; DECLARE query2 TEXT; SET query1 = 'SELECT COUNT(*) bla bla bla.....'; // Query1 to select the count of matching tuples.. SET query2 = 'SELECT * from bla bla bla....'; // Query2 to select original records... // later part of this both queries generate dynamically according to some