Conversion error when converting nvarchar '10, 12 'to int data type
$sSql = "SELECT * FROM table1 where field1 > 0 and field2 IN (:buzzGroups) and active = 1";
$arrParams = array('buzzGroups' => $vBuzzGroups);
$stmt = $this->tableGateway->getAdapter()->createStatement($sSql);
$stmt->prepare($sSql);
$data = $stmt->execute($arrParams);
Here is the meaning $vBuzzGroups = '10,12';
when i pass only one value then it works, but when i try with multiple values. then from comma, it gives me an error,
Conversion failed when converting the nvarchar value '10,12' to data type int
Is there anyone who faced this problem?
+3
kumar
source
to share
1 answer
Use implode () function to split values.
Try this updated code
$arrParams = array('buzzGroups' => $vBuzzGroups);
$sSql = "SELECT * FROM table1 where field1 > 0 and field2 IN
(".implode(',',$arrParams).") and active = 1";
0
Ugur altay
source
to share