472,111 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 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 6796
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

Post your reply

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

Similar topics

6 posts views Thread by Rodusa | last post: by
4 posts views Thread by Brian Shannon | last post: by
10 posts views Thread by John | last post: by
1 post views Thread by john | last post: by
6 posts views Thread by Plissskin | last post: by
reply views Thread by Jay Douglas | last post: by

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.