where-clause

How to specify dynamic field names in a Linq where clause?

流过昼夜 提交于 2019-11-27 07:55:25
If you create a Filter object that contains criteria for Linq that normally goes in a where clause like this: var myFilterObject = FilterFactory.GetBlank(); myFilterObject.AddCondition("Salary", "lessThan", "40000"); var myResult = myRepository.GetEmployees(myFilterObject); How would you match the Linq field to the Field Name without using a big case statement? return from e in db.Employee where e.Salary < 40000 select new IList<EmployeeViewModel> { Name= e.name, Salary= e.Salary }; I assume you need to send an object to the Repository that specifies filtering so that you only pull what

SQLSTATE[42S22]: Column not found: 1054 Unknown column - Laravel

▼魔方 西西 提交于 2019-11-27 07:35:17
问题 I'm using the framework Laravel. I have 2 tables (Users and Members). When I want to login, I get the error message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in 'where clause' (SQL: select * from members where user_email = ? limit 1) (Bindings: array ( 0 => 'test@hotmail.com', )) Table Users CREATE TABLE IF NOT EXISTS `festival_aid`.`users` ( `user_id` BIGINT NOT NULL AUTO_INCREMENT, `user_email` VARCHAR(45) NOT NULL, `user_created` TIMESTAMP NOT NULL DEFAULT

Conversion to datetime fails only on WHERE clause?

房东的猫 提交于 2019-11-27 05:57:50
问题 I'm having a problem with some SQL server queries. Turns out that I have a table with "Attibute_Name" and "Attibute_Value" fields, which can be of any type, stored in varchar. (Yeah... I know.) All the dates for a particular attribute seem to be stored the the "YYYY-MM-DD hh:mm:ss" format (not 100% sure about that, there are millions of records here), so I can execute this code without problems: select /*...*/ CONVERT(DATETIME, pa.Attribute_Value) from ProductAttributes pa inner join

mySQL returns all rows when field=0

随声附和 提交于 2019-11-27 04:37:51
I was making some tests, and it was a surprise when i was querying a table, and the query SELECT * FROM table WHERE email=0 returned all rows from the table. This table has no '0' values and it's populated with regular e-mails. Why this happens? This can lead to serious security problems. Is there a way to avoid this without modifying the query? Am i missing something here? Thanks. This is because it is converting the email field (which I assume is a varchar field) to an integer. Any field without a valid integer will equate to 0. You should make sure that you only compare string fields to

Is a JOIN faster than a WHERE?

筅森魡賤 提交于 2019-11-27 04:09:49
Suppose I have two tables that are linked (one has a foreign key to the other) : CREATE TABLE Document ( Id INT PRIMARY KEY, Name VARCHAR 255 ) CREATE TABLE DocumentStats ( Id INT PRIMARY KEY, DocumentId INT, -- this is a foreign key to table Document NbViews INT ) I know, this is not the smartest way of doing things, but this is the best example I could come up with. Now, I want to get all documents that have more than 500 views. The two solutions that come to my mind are : SELECT * FROM Document, DocumentStats WHERE DocumentStats.Id = Document.Id AND DocumentStats.NbViews > 500 or : SELECT *

Conditional WHERE clause with CASE statement in Oracle

自古美人都是妖i 提交于 2019-11-27 03:06:34
问题 I'm brand-new to the Oracle world so this could be a softball. In working with an SSRS report, I'm passing in a string of states to a view. The twist is that the users could also pick a selection from the state list called "[ No Selection ]" ... (that part was not by doing and I'm stuck with implementing things this way) If they choose the No Selection option, then I just want to return all states by default, otherwise return just the list of states that are in my comma-separated list. This

SQL Server: How to use UNION with two queries that BOTH have a WHERE clause?

帅比萌擦擦* 提交于 2019-11-27 01:17:05
问题 Given: Two queries that require filtering: select top 2 t1.ID, t1.ReceivedDate from Table t1 where t1.Type = 'TYPE_1' order by t1.ReceivedDate desc And: select top 2 t2.ID from Table t2 where t2.Type = 'TYPE_2' order by t2.ReceivedDate desc Separately, these return the ID s I'm looking for: (13, 11 and 12, 6) Basically, I want the two most recent records for two specific types of data. I want to union these two queries together like so: select top 2 t1.ID, t2.ReceivedDate from Table t1 where

Selecting rows where remainder (modulo) is 1 after division by 2?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:40:57
问题 There is a column in options that hold an integer. I want to select the row only if that value % 2 = 1. I know this can be done in 2 queries but is it possible to do it in 1? 回答1: MySQL, SQL Server, PostgreSQL, SQLite support using the percent sign as the modulus: WHERE column % 2 = 1 For Oracle, you have to use the MOD function: WHERE MOD(column, 2) = 1 回答2: At least some versions of SQL (Oracle, Informix, DB2, ISO Standard) support: WHERE MOD(value, 2) = 1 MySQL supports '%' as the modulus

Filter Table Before Applying Left Join

吃可爱长大的小学妹 提交于 2019-11-26 22:15:51
问题 I have 2 tables, I want to filter the 1 table before the 2 tables are joined together. Customer Table: ╔══════════╦═══════╗ ║ Customer ║ State ║ ╠══════════╬═══════╣ ║ A ║ S ║ ║ B ║ V ║ ║ C ║ L ║ ╚══════════╩═══════╝ Entry Table: ╔══════════╦═══════╦══════════╗ ║ Customer ║ Entry ║ Category ║ ╠══════════╬═══════╬══════════╣ ║ A ║ 5575 ║ D ║ ║ A ║ 6532 ║ C ║ ║ A ║ 3215 ║ D ║ ║ A ║ 5645 ║ M ║ ║ B ║ 3331 ║ A ║ ║ B ║ 4445 ║ D ║ ╚══════════╩═══════╩══════════╝ I want to Left Join so I get all

Oracle SQL comparison of DATEs returns wrong result

谁说我不能喝 提交于 2019-11-26 21:57:56
问题 I have REPORTDATE column in database ( DATETIME ) type. I want to extract only DATE value from the DATETIME, then to do COUNT for each day and to put WHERE clause to restrict only dates later than some specific date. So I have this clause: SELECT to_char(REPORTDATE, 'DD.MM.YYYY') AS MY, COUNT(*) from INCIDENT where to_char(REPORTDATE, 'DD.MM.YYYY')>'09.11.2013' GROUP BY to_char(REPORTDATE, 'DD.MM.YYYY') It returns me results but but I can notice wrong result such as : 30.10.2013 which is