IN Clause in Dynamic Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tarunsanju15
    New Member
    • Apr 2007
    • 1

    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
  • write2ashokkumar
    New Member
    • Feb 2007
    • 39

    #2
    Originally posted by tarunsanju15
    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,1 23",")");

    prepare stmt from @vquery;
    execute stmt;


    Regards,
    S.Ashokkumar

    Comment

    • ScarletPimpernal
      New Member
      • Mar 2007
      • 39

      #3
      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


      Originally posted by tarunsanju15
      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

      Comment

      Working...