473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

IN Clause in Dynamic Query

Hi,

I am writing a dynamic query in which i have to select a records depend upon the no. of values entered by user like:
select * from _table where _tableColumn IN (values entered by user)

the values entered come in this format: 456,465,123
bt if i pass this value in string format through a bind variable. The query is not working it is taking whole value as whole..

Please help me out..
I am writing this query in MySql
Apr 22 '07 #1
2 6969
Hi,

I am writing a dynamic query in which i have to select a records depend upon the no. of values entered by user like:
select * from _table where _tableColumn IN (values entered by user)

the values entered come in this format: 456,465,123
bt if i pass this value in string format through a bind variable. The query is not working it is taking whole value as whole..

Please help me out..
I am writing this query in MySql


hi...

for do this, u have to use the dynamic sql.
For example:

user input value is 456,465,123....

first build the query lie this

set @vquery = CONCAT("select * from test_table where table_col in(","456,465,123",")");

prepare stmt from @vquery;
execute stmt;


Regards,
S.Ashokkumar
Apr 23 '07 #2
Hi,

Try this

SET @vValue := '456,465,123';

SET @vquery = CONCAT('select * from test_table where table_col in (', @vValue,');


PREPARE stmt from @vquery;
EXECUTE stmt;


Thanks,
Pimp


Hi,

I am writing a dynamic query in which i have to select a records depend upon the no. of values entered by user like:
select * from _table where _tableColumn IN (values entered by user)

the values entered come in this format: 456,465,123
bt if i pass this value in string format through a bind variable. The query is not working it is taking whole value as whole..

Please help me out..
I am writing this query in MySql
Apr 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rodusa | last post by:
I am beggining to learn stored procedures and I am trying to concatenate the where clause below but I keep getting an error: declare @sqlwhere varchar(15) set @sqlwhere = 'parentid=2' ...
4
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build...
4
by: matt | last post by:
Hi, I'm writing a visual basic application which searches a database of e-mail messages, based on certain criteria. I'm using dynamic SQL and an exec sp_executesql statement on the dynamic sql...
10
by: Phil Latio | last post by:
Probably not the best way to do this, but I'd appreciate it if someone could tell me why the following DOESN'T work; I have a function (code below) which returns a string based upon a supplied...
10
by: John | last post by:
Hi I have a form with tow fields for dates in dd/mm/yyyy format. I am trying to use the fields in a query's where clause as below; "SELECT * " & _ "FROM Orders " & _ " WHERE Orders.)>= #" &...
1
by: aiyaonline | last post by:
I like to know if the following makes any performance issue. select field_1 from table_1 where country ='USA'; (or) select field_1 from table_1 where country in ('USA'); The reason behind is:...
1
by: john | last post by:
I'm trying to build a LINQ expression that will use a dynamic construction of a LIKE statement in the WHERE clause, it would look something like this in SQL: WHERE TaskGroup Like "*00*" OR...
6
by: Plissskin | last post by:
I need to create an "ad-hoc" filtering page in a web app we are building. The page would display a number of drop down lists, text boxes, and radio lists and allow the user to select (enter) some...
20
by: billmaclean1 | last post by:
I need to write a stored procedure that selects from a table and returns the result set. I don't always know the TableSchema that I need to use when qualifying the table at run-time Example:...
0
by: Jay Douglas | last post by:
Hello, I've found some posts on creating dynamic WHERE clauses in LINQ to SQL using predicate builders and extending lamda expressions. One issue with these posts is all the examples only use a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.