Hi Chaps,
Just registering as I am starting to get into TSQL, hoping I can learn and help out when I get some more experience
I am creating a simple procedure for practice, but I just can't work out why it is not working and was hoping someone may be able to assist?
The query is as follows:
CREATE PROCEDURE dbo.AmountOwed
@VendorName Varchar(20) AS
SELECT
VEND.VendorName,
VEND.VendorID,
INV.InvoiceID AS 'Invoice Number',
INV.InvoiceDate,
InvoiceTotal - PaymentTotal AS 'Amount Owed'
FROM dbo.Vendors VEND
JOIN dbo.Invoices INV ON VEND.VendorID = INV.VendorID
WHERE VEND.VendorName LIKE '%'+@VendorName+'%'
I execute it by just entering the standard EXEC (procedurename) 'the'
No results.
I'll run a basic query like so:
SELECT * FROM dbo.Vendors
WHERE VendorName like '%THE%'
Of course it works. So I try my select query:
SELECT
VEND.VendorName,
VEND.VendorID,
INV.InvoiceID AS 'Invoice Number',
INV.InvoiceDate,
InvoiceTotal - PaymentTotal AS 'Amount Owed'
FROM dbo.Vendors VEND
JOIN dbo.Invoices INV ON VEND.VendorID = INV.VendorID
WHERE VEND.VendorName LIKE 'THE'
No results?
I'm clearly missing something very basic, and I am either very stupid or blind, as I can't figure out why that query isn't working.
I'm selecting the relevant fields, joining the two tables on PK / FK and it's just not working.
I would think it was a problem with the two ID's not matching on the tables, but it should do.
Any advice on this would be appreciated, it's driving me nuts.
Many thanks.