Do I need to add a quote to my SQL statement?

53 views Asked by At

This is my current statement. It does not work. It returns 0 results.

SELECT ID,ACCOUNT,Key,MasterKey, key FROM Asset 
    WHERE  MasterKey = $parent_key And Asset = $asset

If I change this statement to hardcoded values:

SELECT ID,ACCOUNT,Key,MasterKey, key FROM Asset 
    WHERE  MasterKey = '1234' And Asset = 'Test'

It works.

The variables are being filled using an IBM tool, Castiron. I'm not sure if I need to consult that group, or just simply add the single quotes around the variable values.

Something like this:

SELECT ID,ACCOUNT,Key,MasterKey, key FROM Asset 
    WHERE  MasterKey = '''' + $parent_key + '''' And Asset = '''' + $asset + ''''

Any thoughts?

2

There are 2 answers

2
affaz On

Try this..Use single quotes for the variables

SELECT ID,ACCOUNT,Key,MasterKey, key FROM Asset WHERE MasterKey = '$parent_key' And Asset = '$asset'
0
Anton Korotkoff On
"SELECT ID, ACCOUNT, Key, MasterKey, key FROM Asset WHERE MasterKey = '{$parent_key}' And Asset = '{$asset}'"

That may help.