in-clause

passing list to IN clause in HQL or SQL?

感情迁移 提交于 2019-11-26 19:23:26
问题 I get List<Strings> by executing a query. This must be passed to another query of IN clause values. How to pass them in HQL ? We can convert List to Array and can pass it, that's not a problem. Finally, I must pass the list in List<String> or Array or String form to the IN clause. 回答1: from AUTOS a where a.model in (select m.model from MODELS m) or Query query1 = session.createQuery("select s.id from Salary s where s.salary < 50000 AND s.salary > 49980"); Query query2 = session.createQuery(

MySQL variable format for a “NOT IN” list of values

梦想与她 提交于 2019-11-26 17:33:44
Going crazy trying to set a variable in a query of type: SET @idcamposexcluidos='817,803,495'; so i can then use it on a WHERE id_campo not in (@idcamposexcluidos) I've tried defining the variable in different formats with no luck and don't seem to find an specific example for the above: SET @idcamposexcluidos='(817,803,495)'; ... WHERE id_campo not in @idcamposexcluidos SET @idcamposexcluidos=817,803,495; with no success. It either returns an error or ignores the values. You can't use the IN clause like that. It compiles to a single string in your IN clause. But an IN clause needs separate

Multiple Id&#39;s in In clause of SQL Query C# [closed]

妖精的绣舞 提交于 2019-11-26 14:57:00
问题 I want to basically use multiple iD's in In clause of my sql query. Now i have two options one is to get the comma separated ID's from a textbox or i can put a list view or grid view to insert id's there and then get the id's to be used in sql statement. Can you please help me with the code, how to do this thing? 回答1: In order to get textbox value you have to code like this:- "select * from table where id in ( "+textbox1.text+")"; But this will lead you to Sql Injection problem. So a better

How to pass a variable to a IN clause?

我与影子孤独终老i 提交于 2019-11-26 14:05:13
问题 Lets say I have a SP that has a SELECT statements as follows, SELECT product_id, product_price FROM product WHERE product_type IN ('AA','BB','CC'); But data goes to that IN clause must be through a single variable that contains the string of values. Something link below SELECT product_id, product_price FROM product WHERE product_type IN (input_variables); But its not working that way. Any idea how to do this? 回答1: Pass parameter value like this - 'AA,BB,CC' . Then, it is enough to use FIND_IN

MySQL number of items within “in clause”

天大地大妈咪最大 提交于 2019-11-26 08:08:11
I have three tables to define users: USER: user_id (int), username (varchar) USER_METADATA_FIELD: user_metadata_field_id (int), field_name (varchar) USER_METADATA: user_metadata_field_id (int), user_id (int), field_value (varchar) I'd like to create a middle tier user that has certain access to other users within the application. To determine which users the logged in use can access, I am using a subquery like the following: SELECT user_id FROM user WHERE user_id IN (SELECT user_id FROM user_metadata WHERE user_metadata_field_id = 1 AND field_value = 'foo') Currently I am storing the subquery

MySQL variable format for a “NOT IN” list of values

我只是一个虾纸丫 提交于 2019-11-26 05:29:34
问题 Going crazy trying to set a variable in a query of type: SET @idcamposexcluidos=\'817,803,495\'; so i can then use it on a WHERE id_campo not in (@idcamposexcluidos) I\'ve tried defining the variable in different formats with no luck and don\'t seem to find an specific example for the above: SET @idcamposexcluidos=\'(817,803,495)\'; ... WHERE id_campo not in @idcamposexcluidos SET @idcamposexcluidos=817,803,495; with no success. It either returns an error or ignores the values. 回答1: You can't

SQL Server - In clause with a declared variable [duplicate]

陌路散爱 提交于 2019-11-26 04:25:54
问题 This question already has an answer here: Parameterize an SQL IN clause 40 answers Let say I got the following : DECLARE @ExcludedList VARCHAR(MAX) SET @ExcludedList = 3 + \', \' + 4 + \' ,\' + \'22\' SELECT * FROM A WHERE Id NOT IN (@ExcludedList) Error : Conversion failed when converting the varchar value \', \' to data type int. I understand why the error is there but I don\'t know how to solve it... 回答1: You need to execute this as a dynamic sp like DECLARE @ExcludedList VARCHAR(MAX) SET

What is the best approach using JDBC for parameterizing an IN clause? [duplicate]

我们两清 提交于 2019-11-26 04:25:34
This question already has an answer here: PreparedStatement IN clause alternatives? 28 answers Say that I have a query of the form SELECT * FROM MYTABLE WHERE MYCOL in (?) And I want to parameterize the arguments to in. Is there a straightforward way to do this in Java with JDBC, in a way that could work on multiple databases without modifying the SQL itself? The closest question I've found had to do with C# , I'm wondering if there is something different for Java/JDBC. There's indeed no straightforward way to do this in JDBC. Some JDBC drivers seem to support PreparedStatement#setArray() on

Linq to Entities - SQL “IN” clause

狂风中的少年 提交于 2019-11-26 03:13:56
问题 In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights IN (\"Admin\", \"User\", \"Limited\") How would you replicate that in a LINQ to Entities query? Is it even possible? 回答1: You need to turn it on its head in terms of the way you're thinking about it. Instead of doing "in" to find the current item's user rights in a predefined set of applicable user rights, you're asking a predefined set of user rights if it contains the current item's applicable value. This is exactly

How to put more than 1000 values into an Oracle IN clause [duplicate]

吃可爱长大的小学妹 提交于 2019-11-26 01:35:39
问题 This question already has answers here : SQL IN Clause 1000 item limit (4 answers) Closed 5 years ago . Is there any way to get around the Oracle 10g limitation of 1000 items in a static IN clause? I have a comma delimited list of many of IDs that I want to use in an IN clause, Sometimes this list can exceed 1000 items, at which point Oracle throws an error. The query is similar to this... select * from table1 where ID in (1,2,3,4,...,1001,1002,...) 回答1: Put the values in a temporary table