question

goza1515 avatar image
goza1515 asked

How do I get my temp table to bind so I can update my records

I am getting the Following Error when i try to run a update to match data from my temp table created. Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "# t.No Response Letter" could not be bound. Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "# T.No Tax Statment" could not be bound. begin tran update contacts Set contacts.NoResponseLetters = #t."No Response Letter",contacts.NoTaxStatements = #T."No Tax Statment" where contacts.contactid in ( select contacts.contactid from contacts Join [dbo].[#t] on dbo.[#t].contactid = contacts.contactid ) Any thoughts??
updatejoinstemporary-tables
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

goza1515 avatar image goza1515 commented ·
Thank you for the Input Guys I was able to get it done. Most of all i learned for next time!
0 Likes 0 ·
Tom Staab avatar image
Tom Staab answered
As Magnus said, the temp table will need to be directly referenced in the update statement rather than in a subquery. Your query reminds me of Oracle syntax, but the way to do this in SQL Server is by joining the tables in a FROM clause. Try this: UPDATE c SET NoResponseLetters = t.[No Response Letter] , NoTaxStatements = t.[No Tax Statement] FROM contacts c INNER JOIN #t t ON t.contactid = c.contactid ;
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
You don't have a FROM clause containing #t, thus you can't reference it in the SET clause. Check Books Online for reference and examples of updates with FROM clauses.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.