where-clause

Swift “where” Array Extensions

删除回忆录丶 提交于 2019-11-30 00:16:33
问题 As of Swift 2.0 it seems we can get closer to extensions of generic types applicable to predicated situations. Although we still can't do this: protocol Idable { var id : String { get } } extension Array where T : Idable { ... } ...we can now do this: extension Array { func filterWithId<T where T : Idable>(id : String) -> [T] { ... } } ...and Swift grammatically accepts it. However, for the life of me I cannot figure out how to make the compiler happy when I fill in the contents of the

WHERE clause in SSRS expression

泄露秘密 提交于 2019-11-29 16:43:40
问题 What's the syntax for inserting a WHERE clause in an SSRS expression ? I am using BIDS 2008 . =Sum(Fields!QuantityToShip.Value) WHERE FIELDS!Program.Value = "FC" The code listed above represents the logic I want to use, but obviously inserting the WHERE in there creates a syntax error. The purpose of this expression is to define a series' value field in a stacked bar chart. Any help would be greatly appreciated! 回答1: Use the IIF method: =Sum(IIF(Fields!Program.Value = "FC", Fields

How to construct Where Expression dynamically in Entity Framework?

随声附和 提交于 2019-11-29 10:24:23
I've taken a look at this answer on how to dynamically create an OrderBy expression in Entity Framework. But I'd like to also build a dynamic Where expression. Something along the lines of this: public IEnumerable<InventoryItem> GetAll(string filterBy, object value) { var results = new List<InventoryItem>(); using (var db = new InventoryDb()) { if (QueryHelper.PropertyExists<InventoryItem>(filterBy)) { var query = db.rri_InventoryItems.WhereByProperty(filterBy, value); foreach(var item in query.Where(expr)) { results.Add(ConvertItem(item)); } } } return results; } Passing in the property to

LIKE and NULL in WHERE clause in SQL

别来无恙 提交于 2019-11-29 09:23:42
I have a store procedure which i have planned to use for search and get all values. Scenario: If the parameter passed is NULL it should return all the values of the table and if the parameter passed is not NULL it should return the values according to the condition which is in LIKE. //Query: ALTER procedure [dbo].[usp_GetAllCustomerDetails] ( @Keyword nvarchar(20) = null ) As Begin Select CustomerId,CustomerName,CustomerTypeName,CustomerCode,CategoryName,CustomerMobile,CustomerEmail,CustomerAddress,CustomerCity,CustomerState,Pincode from tblCustomerMaster CM inner join dbo

MySQL user-defined variable in WHERE clause

早过忘川 提交于 2019-11-29 09:13:28
I want to know if there is a way to use a user-defined variable in WHERE clause, as in this example: SELECT id, location, @id := 10 FROM songs WHERE id = @id This query runs with no errors but doesn't work as expected. Maxym Not far from what Mike E. proposed, but one statement: SELECT id, location FROM songs, ( SELECT @id := 10 ) AS var WHERE id = @id; I used similar queries to emulate window functions in MySQL. E.g. Row sampling - just an example of using variables in the same statement From the MySQL manual page on User Defined Variables : As a general rule, you should never assign a value

Ignore particular WHERE criteria

谁都会走 提交于 2019-11-29 07:30:27
I want to execute a parameterized query to perform a search by user-supplied parameters. There are quite a few parameters and not all of them are going to be supplied all the time. How can I make a standard query that specifies all possible parameters, but ignore some of these parameters if the user didn't choose a meaningful parameter value? Here's an imaginary example to illustrate what I'm going for $sql = 'SELECT * FROM people WHERE first_name = :first_name AND last_name = :last_name AND age = :age AND sex = :sex'; $query = $db->prepare($sql); $query->execute(array(':first_name' => 'John',

Conditional Where clauses in JasperReports

隐身守侯 提交于 2019-11-29 07:05:49
Let's say I want a JasperReport that lets the user filter on a date if they so wish. The SQL is as follows: select * from foo where bar = $P{bar} and some_date > $P{some.date} Now, I don't want to filter by some date if they didn't pass the date in. I found the following kludge that people use: select * from foo where bar = $P{bar} $P!{some.date.fragment} And the some.date.fragment parameter is defined with the following default: ($P{some.date} == null || $P{some.date}.equals("")) ? "" : "AND some_date >'" + new java.sql.Date($P{some.date}.getTime()).toString() + "'" This is not working as the

Order by Maximum condition match

删除回忆录丶 提交于 2019-11-29 07:02:47
Please help me to create a select query which contains 10 'where' clause and the order should be like that: the results should be displayed in order of most keywords(where conditions) matched down to least matched. NOTE: all 10 condition are with "OR". Please help me to create this query. i am using ms-sql server 2005 Like: Select * from employee where empid in (1,2,4,332,434) or empname like 'raj%' or city = 'jodhpur' or salary >5000 In above query all those record which matches maximum conditions should be on top and less matching condition record should be at bottom. SELECT * FROM (SELECT

using CASE in T-SQL in the where clause?

≯℡__Kan透↙ 提交于 2019-11-29 05:57:41
Im trying to use case to vary the value im checking in a where clause but I'm getting the error: incorrect syntax near the keyword 'CASE' SQL Server 2005 select * from table where ((CASE when adsl_order_id like '95037%' then select '000000'+substring(adsl_order_id,6,6) ELSE select adsl_order_id END) not in (select mwebID from tmp_csv_dawis_bruger0105) Randy Minder Here is one way to include a case statement in a Where clause: SELECT * FROM sometable WHERE 1 = CASE WHEN somecondition THEN 1 WHEN someothercondition THEN 2 ELSE ... END You could try SELECT * FROM table WHERE (SELECT CASE WHEN

How to use If Statement in Where Clause in SQL?

橙三吉。 提交于 2019-11-29 05:50:40
I need to use if statement inside where clause in sql. Select * from Customer WHERE (I.IsClose=@ISClose OR @ISClose is NULL) AND (C.FirstName like '%'+@ClientName+'%' or @ClientName is NULL ) AND if (@Value=2) begin (I.RecurringCharge=@Total or @Total is NULL ) end else if(@Value=3) begin (I.RecurringCharge like '%'+cast(@Total as varchar(50))+'%' or @Total is NULL ) end Note:This is not the complete code.Everything is defined in SP.I Just written the code that was needed to understand the issue. Thanks in advance. You have to use CASE Statement/Expression Select * from Customer WHERE (I