where-clause

When to use lambda expressions instead of a Where clause in LINQ

守給你的承諾、 提交于 2019-12-03 13:31:20
问题 I've been really digging into LINQ, and I'm trying to hash out this lambda expression business. I'm just not seeing the benefit of some of the nuances of the syntax. Primarily, it seems to me that a lambda expression is mostly just a different way of using a Where clause. Why wouldn't I just use a Where clause then? Is the lambda expression more efficient? Is it just another syntactical addition to draw programmers from another group to feel more comfortable in C#? Are there other better use

Beginner SQL section: avoiding repeated expression

混江龙づ霸主 提交于 2019-12-03 12:04:59
I'm entirely new at SQL, but let's say that on the StackExchange Data Explorer , I just want to list the top 15 users by reputation, and I wrote something like this: SELECT TOP 15 DisplayName, Id, Reputation, Reputation/1000 As RepInK FROM Users WHERE RepInK > 10 ORDER BY Reputation DESC Currently this gives an Error: Invalid column name 'RepInK' , which makes sense, I think, because RepInK is not a column in Users . I can easily fix this by saying WHERE Reputation/1000 > 10 , essentially repeating the formula. So the questions are: Can I actually use the RepInK "column" in the WHERE clause?

Doctrine: Multiple (whereIn OR whereIn) query?

别等时光非礼了梦想. 提交于 2019-12-03 11:50:40
问题 I'm having trouble crafting a fairly simple query with Doctrine... I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like: ->whereIn('country', 'city', $countries, $cities) ... with 'country' being a WHERE IN for $countries and 'city' being a WHERE IN for $city. I could separate the two out but the needed query has lots of other conditions so that's not possible. The resulting SQL I'm after would

T-SQL Where Clause Case Statement Optimization (optional parameters to StoredProc)

烂漫一生 提交于 2019-12-03 11:32:58
问题 I've been battling this one for a while now. I have a stored proc that takes in 3 parameters that are used to filter. If a specific value is passed in, I want to filter on that. If -1 is passed in, give me all. I've tried it the following two ways: First way: SELECT field1, field2...etc FROM my_view WHERE parm1 = CASE WHEN @PARM1= -1 THEN parm1 ELSE @PARM1 END AND parm2 = CASE WHEN @PARM2 = -1 THEN parm2 ELSE @PARM2 END AND parm3 = CASE WHEN @PARM3 = -1 THEN parm3 ELSE @PARM3 END Second Way:

LINQ Where with AND OR condition

心不动则不痛 提交于 2019-12-03 09:33:45
So I have managed to get this query working List<string> listStatus = new List<string>() ; listStatus.add("Text1"); List<string> listMerchants = new List<string>() ; listMerchants.add("Text2"); from item in db.vw_Dropship_OrderItems where listStatus.Contains(item.StatusCode) && listMerchants.Contains(item.MerchantId) select item; Here I would like to check if listStatus and listMerchants are not null only then put them inside WHERE clause. Like if listMerchants is null then query will be like where listStatus.Contains(item.StatusCode) I do not want to use switch or If condition. Thanks from

MySql Inner Join with WHERE clause [closed]

独自空忆成欢 提交于 2019-12-03 08:19:39
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Here is my code: SELECT table1.f_id FROM table1 WHERE table1.f_com_id = '430' AND table1.f_status = 'Submitted' INNER JOIN table2 ON table2.f_id = table1

Dynamic Or Clause Linq

最后都变了- 提交于 2019-12-03 08:12:23
Today we currently have a statement like this: var Query = (from dp in db.Patients select dp); var UserID = User.Identity.GetUserId(); if (User.IsInRole("Administrator")) { Query = Query.Where(x => x.AdministratorID == UserID); } if (User.IsInRole("Counselor")) { Query = Query.Where(x => x.CounselorID == UserID); } if (User.IsInRole("Physician")) { Query = Query.Where(x => x.PhysicianID == UserID); } The problem is we have Users that can have multiple roles. If a User is both an Counselor and Physician we want the system to pull back all patients where CounselorID == UserID or PhysicianID ==

Laravel where on relationship object

心已入冬 提交于 2019-12-03 05:25:52
问题 I'm developing a web API with Laravel 5.0 but I'm not sure about a specific query I'm trying to build. My classes are as follows: class Event extends Model { protected $table = 'events'; public $timestamps = false; public function participants() { return $this->hasMany('App\Participant', 'IDEvent', 'ID'); } public function owner() { return $this->hasOne('App\User', 'ID', 'IDOwner'); } } and class Participant extends Model { protected $table = 'participants'; public $timestamps = false; public

SQL - improve NOT EXISTS query performance

倖福魔咒の 提交于 2019-12-03 05:18:39
Is there a way I can improve this kind of SQL query performance: INSERT INTO ... WHERE NOT EXISTS(Validation...) The problem is when I have many data in my table (like million of rows), the execution of the WHERE NOT EXISTS clause if very slow. I have to do this verification because I can't insert duplicated data. I use SQLServer 2005 thx Make sure you are searching on indexed columns, with no manipulation of the data within those columns (like substring etc.) Off the top of my head, you could try something like: TRUNCATE temptable INSERT INTO temptable ... INSERT INTO temptable ... ... INSERT

When to use lambda expressions instead of a Where clause in LINQ

爱⌒轻易说出口 提交于 2019-12-03 04:32:05
I've been really digging into LINQ, and I'm trying to hash out this lambda expression business. I'm just not seeing the benefit of some of the nuances of the syntax. Primarily, it seems to me that a lambda expression is mostly just a different way of using a Where clause. Why wouldn't I just use a Where clause then? Is the lambda expression more efficient? Is it just another syntactical addition to draw programmers from another group to feel more comfortable in C#? Are there other better use cases for lambda expressions that I just haven't exposed to yet? Andreas Grech Take a look at this