where-clause

Conditional WHERE clause in SQL Server

浪子不回头ぞ 提交于 2019-11-26 00:15:52
问题 I am creating a SQL query in which I need a conditional where clause. It should be something like this: SELECT DateAppr, TimeAppr, TAT, LaserLTR, Permit, LtrPrinter, JobName, JobNumber, JobDesc, ActQty, (ActQty-LtrPrinted) AS L, (ActQty-QtyInserted) AS M, ((ActQty-LtrPrinted)-(ActQty-QtyInserted)) AS N FROM [test].[dbo].[MM] WHERE DateDropped = 0 --This is where i need the conditional clause AND CASE WHEN @JobsOnHold = 1 THEN DateAppr >= 0 ELSE DateAppr != 0 END The above query is not working

SELECTING with multiple WHERE conditions on same column

…衆ロ難τιáo~ 提交于 2019-11-25 23:40:12
问题 Ok, I think I might be overlooking something obvious/simple here... but I need to write a query that returns only records that match multiple criteria on the same column... My table is a very simple linking setup for applying flags to a user ... ID contactid flag flag_type ----------------------------------- 118 99 Volunteer 1 119 99 Uploaded 2 120 100 Via Import 3 121 100 Volunteer 1 122 100 Uploaded 2 etc... in this case you\'ll see both contact 99 and 100 are flagged as both \"Volunteer\"

Dynamic where clause (OR) in Linq to Entities

为君一笑 提交于 2019-11-25 23:32:11
问题 In the post here I learned how to build a dynamic query using the deferred execution of Linq. But the query is actually using an AND concatenation of the WHERE condition. How can I achieve the same query but with an OR logic? Due to the Flags enum, the query should search for Username , WindowsUsername or both : public User GetUser(IdentifierType type, string identifier) { using (var context = contextFactory.Invoke()) { var query = from u in context.Users select u; if (type.HasFlag

SQL join: where clause vs. on clause

痴心易碎 提交于 2019-11-25 22:56:48
问题 After reading it, this is not a duplicate of Explicit vs Implicit SQL Joins. The answer may be related (or even the same) but the question is different. What is the difference and what should go in each? If I understand the theory correctly, the query optimizer should be able to use both interchangeably. 回答1: They are not the same thing. Consider these queries: SELECT * FROM Orders LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID WHERE Orders.ID = 12345 and SELECT * FROM Orders LEFT JOIN

EF: Include with where clause

纵然是瞬间 提交于 2019-11-25 21:49:15
问题 As the title suggest I am looking for a way to do a where clause in combination with an include. Here is my situations: I am responsible for the support of a large application full of code smells. Changing too much code causes bugs everywhere so I am looking for the safest solution. Let\'s say I have an object Bus and an object People(Bus has a navigation prop Collection of People). In my Query I need to select all the Busses with only the Passengers that are awake. This is a simplistic dummy