Solved

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

Posted on 2016-08-25
6
29 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
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

809 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