I am passing string, but in mysql query not executed. because IN not taking integers please check and solve this one.
My query not working

   SELECT * FROM `employee` WHERE  `employee_id` IN 
    (1001,a/bb/001,a/bb/002,a/bb/003,a/bb/004,a/bb/005,a/bb/006,a/bb/007,a/bb/008,a/bb/009,a/bb/010,a/bb/011,a/bb/012) ORDER BY employee_name ASC



correct one is


    SELECT * FROM `employee` WHERE  `employee_id` IN 
    ('1001','a/bb/001','a/bb/002','a/bb/003','a/bb/004','a/bb/005','a/bb/006','a/bb/007','a/bb/008','a/bb/009','a/bb/010','a/bb/011,'a/bb/012') ORDER BY employee_name ASC



how to convert 


    1001,a/bb/001,a/bb/002,a/bb/003,a/bb/004,a/bb/005,a/bb/006,a/bb/007,a/bb/008,a/bb/009,a/bb/010,a/bb/011,a/bb/012 to

    '1001','a/bb/001','a/bb/002','a/bb/003','a/bb/004','a/bb/005','a/bb/006','a/bb/007','a/bb/008','a/bb/009','a/bb/010','a/bb/011,'a/bb/012'

.

Dani AI

Generated

The error happens because the SQL parser does not see those comma-separated tokens as string literals. Mixed values that contain letters or slashes must be quoted so they are treated as strings. The practical fix is to split the CSV in application code, quote or bind each item, and then run the IN list — not to try to force MySQL to reinterpret an unquoted token list.

A safe, common pattern is to build an IN clause with positional placeholders and execute a prepared statement. Example (PHP/PDO style):

$values = array_map('trim', explode(',', $csv));               // split CSV
$placeholders = implode(',', array_fill(0, count($values), '?'));
$sql = sprintf('SELECT * FROM %s WHERE %s IN (%s)', 'employee', 'employee_id', $placeholders);
$stmt = $pdo->prepare($sql);
$stmt->execute($values);
$rows = $stmt->fetchAll();

If prepared statements are not available, use the DB API's quoting function for every value (never concatenate raw input). For MySQL-specific quick fixes, FIND_IN_SET can match a comma list but prevents index use and is slower; changing the column type to VARCHAR is necessary if values include non-numeric text.

’s note about CAST won’t help if tokens are syntactically invalid as unquoted literals, and ’s client-side toString is only useful while building the parameter values — it does not substitute for proper quoting or parameterization on the server. Finally, prioritize prepared statements (or proper per-value quoting) to avoid SQL injection and type mismatches.

Recommended Answers

All 2 Replies

What language are you calling this from? In any case, you should be able to use the cast(val,type) mysql function to do what you want. IE:
IN (cast(1001,varchar),cast(a/bb/001,varchar),...)

I have no idea what mySQL is like, and I have no experience with it. However, if you are EVER planning on using JavaScript, you can use the .toString() function, as in:
var fdsa = 1234;
var fdsa2 = fdsa.toString();
var fdsa3 = fdsa2.length;

That kind of thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.