multi-part identifier could not be bound
Hi, I'm having an issue with my SQL Statement. I'm trying to declare a variable and set it to the count of the number of records that exist for a particular order number. The problem is when I execute the statement I get this error:
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "prod.dbo.HEADERS.ORDER_NUMBER" could not be bound.
I'm 100% Sure everything is spelled correctly and capitalized properly. This is the code I'm trying to run:
DECLARE @test INT
SET @test = (SELECT COUNT(*) FROM [prod].[dbo].[LINES] WHERE [ORDER_NUMBER] = [prod].[dbo].[HEADERS].[ORDER_NUMBER])
Any idea what might be causing this? Thank you.
The query doesn't make any sense. Think about it: What is [prod].[dbo].[HEADERS].[ORDER_NUMBER]?
I'm not a database guy, and I'm sure I'm definitely missing something, but what I intended it to be is the [database].[schema].[Table].[Column]
Originally Posted by svidgen
Hehe ... OK.
So, [prod].[dbo].[HEADERS].[ORDER_NUMBER] doesn't refer to an ORDER_NUMBER from any particular row. You need to specify a row, or you need to be performing a JOIN.
(with nothing to catch it!)
... COUNT(ORDER_NUMBER) ...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)