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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table variable and ambiguous column

Status
Not open for further replies.

icrf

Programmer
Dec 4, 2001
1,300
US
I'm having issues resolving the ambiguity of column names with a table variable. A short example:
Code:
declare @Inventory table(
	ProductID int,
	Quantity int
)

UPDATE @Inventory SET ProductID = NewProductID FROM tblNewProducts 
WHERE tblNewProducts.ProductID = @Inventory.ProductID
It gives me the error
Must declare the variable '@Inventory'.
If I comment out the WHERE clause, it parses fine. Dropping the table variable prefix bring the expects ambiguous column error.

Is there some other syntax for this?
 
What about this:
Code:
UPDATE I
SET ProductID = NewProductID 
FROM @Inventory I
INNER JOIN tblNewProducts
ON tblNewProducts.ProductID = I.ProductID
 
Looks good, works better. I kept trying to alias the table on its first reference (between UPDATE and SET) with results as poor as you'd expect.

Thanks for the quick reply.

________________________________________
Andrew

I work for a gift card company!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top