Can this be done in SQL?

I am trying to get a buyernumber from a SQL table. Doesn't seem to want to pull the information out of the table though.

Here is what I have:

I have a variable:

newItemNum = 7962525;

I have a table in my sql database that has 2 columns, itemnumber and buyernumber.

Here is my SQL statement:

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE 'newItemNum%';"

The itemnumber in the table is: 7962525 Movie Set

It's going into the table and not finding anything.

Answers


Change this

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE 'newItemNum%';"

To

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE '"+newItemNum+"%';"

LIKE 'newItemNum%' 

is a literal match. you have to parameterize newItemNum

LIKE @newItemNum + '%'

or if you don't wanna mess with params, do this:

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE '" + newItemNum + "%';"

EDIT:

If you're dynamically acquiring table names use something like this:

var buyer="Costco";
var supplier="HomeDepot";
var newItemNum="123445656";

var strSQL = "select BuyerNumber from " +buyer+ "_" + supplier + "xref where Itemnumber LIKE '" + newItemNum + "%';"

Your SQL string needs to use a variable. Replace

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE 'newItemNum%';"

with

strSQL = "select BuyerNumber from %buyer%_%supplier%xref where Itemnumber LIKE @newItemNum + '%';"

Need Your Help

Session with mod_rewrite

apache mod-rewrite

iam using mod-rewrite to create human readable urls. (POST: Mod rewrite - make link readable)