where-clause

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

一曲冷凌霜 提交于 2019-12-28 02:48:05
问题 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

Detect if value is number in MySQL

倾然丶 夕夏残阳落幕 提交于 2019-12-27 10:22:41
问题 Is there a way to detect if a value is a number in a MySQL query? Such as SELECT * FROM myTable WHERE isANumber(col1) = true 回答1: This should work in most cases. SELECT * FROM myTable WHERE concat('',col1 * 1) = col1 It doesn't work for non-standard numbers like 1e4 1.2e5 123. (trailing decimal) 回答2: You can use Regular Expression too... it would be like: SELECT * FROM myTable WHERE col1 REGEXP '^[0-9]+$'; Reference: http://dev.mysql.com/doc/refman/5.1/en/regexp.html 回答3: If your data is

Access- Open form with where clause

徘徊边缘 提交于 2019-12-25 08:49:56
问题 I need to open a specific form by a click on a subform record name. The name in the subform is showed as a combobox with ID and Name as columns. I did like this: Private Sub ID_Prodotto_DblClick(Cancel As Integer) Dim Id As Integer Id = Me.ID_Prodotto.Column.Value DoCmd.OpenForm "Prodotto", , , "ID_Prodotto = " & Id End Sub But Access requires me to manually insert the ID Field Value as I click on the record. Where am I wrong? 回答1: It should read: Id = Me!ID_Prodotto.Value or, if you wish to

Postgresql - Condition on where clause with join

大城市里の小女人 提交于 2019-12-25 08:08:48
问题 I am trying to add a join for a particular condition to my query: select * from ( select row_number() over (partition by dl.value order by random()) as rn, dl.value, q.question_text, q.option_a, q.option_b, q.option_c, q.option_d, q.correct_answer, q.image_link, q.question_type from questions_bank q inner join sports_type st on st.id = q.sports_type_id inner join difficulty_level dl on dl.id = q.difficulty_level_id where st.game_type = lower('cricket') and dl.value in ('E','M','H') ) s where

TSQL where on xml data type

雨燕双飞 提交于 2019-12-25 05:06:54
问题 How does one execute where clause command on a xml data type in Sql Server 2005 ? Xml Structure <User UserId="1" UserName="x"> <User UserId="2" UserName="y"> Query SELECT XmlColumn from Table where XmlColumn.query('/User[@UserId'+ @dynamicValue +']') Intended Output Get all the user tags where the attribute UserId = input variable 回答1: declare @T table ( XMLColumn xml ) insert into @T values ('<User UserId="1" UserName="x"/>') insert into @T values ('<User UserId="2" UserName="y"/>') declare

use WHERE CLAUSE for search data from A date until B date

浪尽此生 提交于 2019-12-24 16:27:47
问题 lets say i have two drop down list and one button on my search page: From <select id="1stdate"> Until <select id="2nddate"> <input type="button" id="search"> i want to search data from 1stdate until 2nddate , how to use WHERE CLAUSE for this case? for ex. i want to search data "from 09-2010 until 11-2010". this my query: SELECT CONCAT( YEAR(Inspection_datetime ),'-',LPAD(MONTH(Inspection_datetime),2,'0')) FROM `inspection_report` GROUP BY CONCAT( MONTH(Inspection_datetime ),YEAR(Inspection

How to retrieve data based on two conditions given?

柔情痞子 提交于 2019-12-24 15:10:01
问题 In MainActivity, I want the listView display the data with a specific month. public void BuildList() { sqlcon.open(); // object of InfoAPI Calendar cal = Calendar.getInstance(); int month = cal.get(Calendar.MONTH)+1; Toast.makeText(getApplicationContext(),month+"",Toast.LENGTH_LONG).show(); Cursor cursor1=sqlcon.readData(month); String[] columns=new String[]{ MyDatabaseHelper.Date,MyDatabaseHelper.TimeIn_Info,MyDatabaseHelper.TimeOut_Info }; int[] to=new int[] { R.id.date,R.id.timeIn,R.id

ZF2 Query WHERE clause with DATE() for datetime column

断了今生、忘了曾经 提交于 2019-12-24 10:55:43
问题 I have a column with datetime data type and I want to build a SQL query in Zend Framework2 which compare date part with user input date. Need to build similar part as DATE(datetime column) = '2014-09-16' with; $select->where(); would be very grateful if someone could help on this. 回答1: Use like this: $date = '2014.05.24'; $select->where('date(expecting_date) = "'.$date.'"'); 回答2: You should use predicate expression for these kind of conditions, like : $select = new \Zend\Db\Sql\Select(table

How to SELECT * with multiple WHERE using fetch_assoc in prepared statements in PHP-MYSQL?

徘徊边缘 提交于 2019-12-24 10:23:09
问题 It's been two days and I have not found any solution for this on Google, so please help. I have to SELECT * from one row with multiple WHERE clauses, using a prepared statements, I want to retrieve the results using fetch_assoc so that I don't have to bind variables using bind_result() , using fetch_assoc I can print many columns as $row['column_name'] . My code is below and it's not running, giving no error. $query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?'; if ($stmt

SQL where clause with case statement

夙愿已清 提交于 2019-12-24 09:29:43
问题 I have a problem with SQL that I have not yet found a solution to, what im trying to do is a where clause for a procedure where a userID variable can contain either a valid userID or -1 to indicate all users. However im stuck at this part of the where clause: AND usertable.userid = CASE WHEN @user = -1 THEN ELSE @user END I'm not sure how to process the -1 to say select all users Thanks 回答1: Perhaps the following would work: SELECT whatever FROM wherever WHERE something = somethingelse AND