Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure parameter problems

Status
Not open for further replies.

plazmo

Programmer
Dec 3, 2005
3
US
i shortned this procedure. but im havving problems with the like clause in this, it says it cannot find the column which i dont understand

CREATE PROC spBalanceRange
@VendorVar VARCHAR(50) = NULL,
AS
DECLARE @QUERY VARCHAR(1000)
SET @QUERY = 'SELECT VendorName, InvoiceNumber, PaymentTotal AS Balance
FROM Invoices JOIN Vendors
ON Invoices.VendorID = Vendors.VendorID '


IF @VendorVar IS NOT NULL
SET @QUERY = @QUERY + 'WHERE VendorName LIKE ' + @VendorVar + ') '

SET @QUERY = @QUERY + ' ORDER BY PaymentTotal DESC'

EXEC (@QUERY)
 

Perhaps you meant to say
[tt]
+ 'WHERE VendorName LIKE ' + @VendorVar + '% '
[/tt]
 
no i just forgot to delete that ')' before posting but more detail on my problem is this:

if i type this:
exec spBalanceRange @VendorVar = 'Vendor'
i get this error:
Invalid column name 'Vendor'.

so if it using a column name:
exec spBalanceRange @VendorVar = 'VendorName'

it runs it.

i dont understand how/why it using a column after my 'LIKE'
 
thank you r937 that worked although i used it without the %

it irritates me tho because i tried this once and it didnt work. but works great now thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top