Solved

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

Posted on 2016-08-25
6
21 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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:jeff-h
Comment Utility
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
Comment Utility
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
Comment Utility
You saved my day, I can't believe I missed that.  Thanks a million!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now