where-clause

Stored Procedure dynamic / generic where

依然范特西╮ 提交于 2019-12-12 02:52:14
问题 I know there a several Answers to this question but it i thing non of them fit my needs so here comes my question based on this SQL Fiddle i will explain you what i'm trying to achieve. How you can see it's just a simple table of persons so now i want to get a person by his id so i have to write a simple query SELECT * FROM Persons WHERE PersonID =@PersonID; to get him i can do this now for any possible combination and i will get tons of stored procedures just for this Table So here is my

Entity Framework Views and Linq .Where

落爺英雄遲暮 提交于 2019-12-12 01:18:44
问题 I have a very small entity framework setup containing only a few related classes/tables and a view. I need to be able to pull a specific record from this view, namely, I need to be able to grab the record that meets two criteria, it has a specific ProfileID and a specific QuoteID . This line is what's causing the problem: TWProfileUpchargeTotal upchargeTotals = _context.TWProfileUpchargeTotals.Where(p => p.Profileid == profile.id && p.quoteid == _quote.quoteid).First(); I'm looping through

PostgreSQL query where date oldest

别说谁变了你拦得住时间么 提交于 2019-12-12 00:50:40
问题 I have a table in Postgres called calendar and I am trying to query the first date value stored where year=2013. I have written the following query which works, however I am wondering if I can query the first date instead of just getting all data and limiting just to one? SELECT date FROM calendar WHERE year=2013 ORDER BY date ASC LIMIT 1 回答1: -- the schema DROP SCHEMA lutser CASCADE; CREATE SCHEMA lutser; SET search_path='lutser'; -- the table CREATE TABLE years ( zdate DATE NOT NULL PRIMARY

JPQL - Update with Multiple where conditions

泄露秘密 提交于 2019-12-12 00:23:44
问题 Does JPQL support the following Update? Update Person p set p.name = :name_1 where p.id = :id_1, p.name = :name_2 where p.id = :id_2, p.name = :name_3 where p.id = :id_3 If not, are there any alternatives? I tried it myself. But createQuery returned null. 回答1: Case expression is supported in JPA 2.0. I have provided pseudo-code, can make modifications accordingly. You can try below JPQL query using CASE . Update Person p set p.name = CASE WHEN (p.id = :id1) THEN :name_1 WHEN (p.id = :id2)

SQL Server parameterized query with a WHERE clause with Nulls

允我心安 提交于 2019-12-11 23:47:14
问题 VB.NET 2012, ADO.NET, SQL Server 2014 I setup a parameterized query that works well. I essentially read records from a DataTable that comes from a different source than my SQL Server. It's small enough that I elected to read record by record and build a query and hit the SQL Server for a match. However I am having trouble getting a match when one of my fields is supposed to be matched for a null. I know a record exist because I can look at it in SQL Server directly and see it. With my

Avoiding repetitive conditions in the select case and where clause

社会主义新天地 提交于 2019-12-11 23:37:35
问题 I have a table say TAB1 with the following columns - USER_ID NUMBER(5), PHN_NO1 CHAR(20), PHN_NO2 CHAR(20) I have to fetch records from TAB1 into another table TAB2 such that all records with either one of the two or both PHN_NO1 and PHN_NO2 are of length 10 and begin with 5. If in a record,say only PHN_NO1 satisfies the condition and PHN_NO2 does not then, TAB2.P1 should be same as TAB1.PHN_NO1 but TAB2.P2 should be NULL. If neither of the two satisfy the condition, then the record should

WHERE clause in sub-query

╄→гoц情女王★ 提交于 2019-12-11 20:18:38
问题 Following SQL query: select * from er_101 where cd_relnaam IN ( select cd_relnaam from er_101 group by cd_relnaam having count(*) > 1) AND ld_relopdrachtgever = '1' Though I need to have that sub query also limits on ld_relopdrachtgever = '1' How is that possible with an HAVING statement? 回答1: You can also use WHERE in sub-query. SELECT * FROM er_101 WHERE cd_relnaam IN ( SELECT cd_relnaam FROM er_101 WHERE ld_relopdrachtgever = '1' <--You can add WHERE clause before GROUP BY --^^^^^----

How to query and calculate dates in the where clause of a LINQ statement?

空扰寡人 提交于 2019-12-11 19:37:45
问题 I am having trouble with the following piece of code. Before I paste it, Let me give a bit of history on what should happen. I have a model containing 2 fields of interest at the moment, which is the name of the order the customer placed, and the date at which he/she placed it. A pre-calculated date will be used to query the dateplaced field (and should only query the dates , and not the time). The query counts the amount of duplicates that occur in the MondayOrder field, and groups them

Postgres where clause over two columns

五迷三道 提交于 2019-12-11 15:33:47
问题 Database - I am working on in Postgres 9.6.5 I am analyzing the data from US Airport Authority (RITA) about the flights arrival and departures. This link (http://stat-computing.org/dataexpo/2009/the-data.html) lists all the columns in the table. The table has following 29 columns No Name Description 1 Year 1987-2008 2 Month 1-12 3 DayofMonth 1-31 4 DayOfWeek 1 (Monday) - 7 (Sunday) 5 DepTime actual departure time (local, hhmm) 6 CRSDepTime scheduled departure time (local, hhmm) 7 ArrTime

Retrieve MySQL data using where clauses

穿精又带淫゛_ 提交于 2019-12-11 14:09:44
问题 I'm wonder how to use WHERE clauses to get the data from MySQL and finally load to android listView ? I want to get the date , timeIn and timeOut based on the name and month. This is what I have tried so far. GetData public void getData(String name, String month) { class GetDataJSON extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); HttpPost httppost = new HttpPost