Solved

SQL Server 2016 Insert statement not working.  table could not be bound error.

Posted on 2016-08-25
6
33 Views
Last Modified: 2016-08-25
Hello All,
I'm having an issue with an insert statement that I think is ok but giving me a "Table could not be bound" error.  I'm simply trying to insert records from a table on one server to a table on another server.  Originally I used a "Not In" statement that worked on the QCID fields, but since we updated to SQL 2016 and the database has grown the 'Not In' times out and crashes the job.  Here is what I have so far.:

INSERT INTO [Server].[Database].dbo.tblOrderItemSize (QCID,JoxID,Parent,Whs,OrderNum,LineNum,[Assembly],GlassSize,SashSize,FrameSize,AssyLoc,QNADesc,DateStamp,GridType,GridLayout, IGThick) 

SELECT QCID,JoxID,Parent,Whs,OrderNum,LineNum,[Assembly],GlassSize,SashSize,FrameSize,AssyLoc,QNADesc,DateStamp,GridType,GridLayout, IGThick

FROM tblImportSize

WHERE  (Whs = 105) AND (GlassSize is not null) AND (NOT EXISTS (Select * from [Server].[Database].dbo.tblOrderItemSize WHERE tblImportSize.QCID = [Server].Database.dbo.tblOrderItemSize.QCID))

Open in new window


This statement gives me a "Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "[Server].[Database].dbo.tblOrderItemSize.QCID" could not be bound." error


Any help would be greatly appreciated.  Thank you in advance!
Jeff
0
Comment
Question by:jeff-h
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41770542
<wild knee-jerk reaction>  

By any chance is QCID an identity column that does not allow values to be explicitly inserted into it unless SET IDENTITY_INSERT OFF is executed?
0
 

Author Comment

by:jeff-h
ID: 41770567
On the source table it is an identity column but on the destination table it is not.  When I use
WHERE ( Whs = 105 ) AND ( GlassSize IS NOT NULL ) AND (QCID > (SELECT MAX (QCID)FROM [Server].Database.dbo.tblOrderItemSize))

Open in new window

It goes right through.  The problem is that I was missing records this way.
0
 
LVL 8

Expert Comment

by:Randy Peterson
ID: 41770569
So the issue is in  the not exist clause of your statement.

see below...

Select * from [Server].[Database].dbo.tblOrderItemSize WHERE tblImportSize.QCID = [Server].Database.dbo.tblOrderItemSize.QCID

Everything else looks good until the "tblImportSize.QCID = [Server].Database.dbo.tblOrderItemSize.QCID"

You are comparing a QCID to a table value QCID.

One thing you could do is change it to:

Select * from [Server].[Database].dbo.tblOrderItemSize WHERE tblImportSize.QCID in select QCID from [Server].Database.dbo.tblOrderItemSize.QCID

That will match any QCID that is already in the table and won't insert a new one in.

Hope that helps.
0
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 

Author Comment

by:jeff-h
ID: 41770623
OK, I changed the last line to this:  
WHERE  (Whs = 105) AND (GlassSize is not null) AND NOT EXISTS (Select * from ([Server].[Database].dbo.tblOrderItemSize) WHERE (tblImportSize.QCID) IN (Select QCID From [Server].Database.dbo.tblOrderItemSize)

Open in new window

I keep getting Msg 102, Level 15, State 1, Line 7 Incorrect syntax near ')'. error.
0
 
LVL 8

Accepted Solution

by:
Randy Peterson earned 500 total points
ID: 41770665
You are just having a parenthesis error.  Try this:

INSERT INTO [Server].[Database].dbo.tblOrderItemSize (QCID,JoxID,Parent,Whs,OrderNum,LineNum,[Assembly],GlassSize,SashSize,FrameSize,AssyLoc,QNADesc,DateStamp,GridType,GridLayout, IGThick)
SELECT QCID,JoxID,Parent,Whs,OrderNum,LineNum,[Assembly],GlassSize,SashSize,FrameSize,AssyLoc,QNADesc,DateStamp,GridType,GridLayout, IGThick
FROM tblImportSize
WHERE  (Whs = 105) AND (GlassSize is not null) AND (NOT EXISTS (Select * from [Server].[Database].dbo.tblOrderItemSize WHERE tblImportSize.QCID IN (Select QCID From [Server].Database.dbo.tblOrderItemSize)))
0
 

Author Closing Comment

by:jeff-h
ID: 41770682
You saved my day, I can't believe I missed that.  Thanks a million!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question