Sven
Sven

Reputation: 23

PERL: Cant use variables in Sybase SQL Driver to MS SQL Server

I'm trying to use a dynamically constructed query to get data from an ms sql server(2008) in perl.

The sql-string looks like this:

$sql = (q/SELECT COUNT(DISTINCT COLUMNa) FROM TABLEa WHERE COLUMNb = '$var'/);

When I try to execute this I get the following error message:

DBD::Sybase::st execute failed:
  Server message number=245 severity=16 state=1 line=1 server=HOSTNAME
  text=Conversion failed when converting the varchar value '$var' to data type tinyint.
  at ./scriptname.pl line 32.

Upvotes: 2

Views: 114

Answers (1)

Hambone
Hambone

Reputation: 16397

q() is literal. You need qq() if you want $var interpolated.

$sql = qq/SELECT COUNT(DISTINCT COLUMNa) FROM TABLEa WHERE COLUMNb = '$var'/;

Also, I agree with the comment on SQL injection. You should use a bind variable instead.

Upvotes: 3

Related Questions