3 Replies - 1064 Views - Last Post: 15 February 2013 - 08:59 AM

#1 Bladewing51  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 26-August 11

Insert into using 2 joined tables and an FK

Posted 14 February 2013 - 03:55 PM

So I have 2 tables Contacts and Logs, contacts tracks my contacts info and logs tracks the invoices and info on the work I have done during that invoice date.

I have them full joined using a self incrementing primary key ID in Contacts.ID and a normal ID column in Logs.ID which I can query fine and pull up any relevant data using select.

My issue is I'm trying to save data using update to 2 specific columns (Date, Info) in an existing row on my logs table, from my app but the syntax doesn't seem to qualify and continually throws errors at me.

I've tried several different ways but I feel this is the closest I've come yet.

Insert into (Date, Info) values (@Date, @Info) from Contacts full join Logs on Contacts.ID=Logs.ID where Log_ID = 23



Is This A Good Question/Topic? 0
  • +

Replies To: Insert into using 2 joined tables and an FK

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 769
  • Joined: 27-June 09

Re: Insert into using 2 joined tables and an FK

Posted 14 February 2013 - 04:35 PM

Quote

My issue is I'm trying to save data using update to 2 specific columns (Date, Info) in an existing row on my logs table


I'm confused. Do you need to insert new data or update existing data in your table? insert is for creating a new row and update is used to modify existing rows.

To perform an update would be
UPDATE Logs
SET Date=@Date, Info=@Info
WHERE Log_ID = 23


Was This Post Helpful? 1
  • +
  • -

#3 Bladewing51  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 26-August 11

Re: Insert into using 2 joined tables and an FK

Posted 15 February 2013 - 08:07 AM

You are correct I am updating not creating, although strangely I have had no problems with using UPDATE in the past.

Even with that said the code you supplied errors at line 1 logs says "Invalid Object name logs".

:censored:
Was This Post Helpful? 0
  • +
  • -

#4 Bladewing51  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 26-August 11

Re: Insert into using 2 joined tables and an FK

Posted 15 February 2013 - 08:59 AM

Scratch my last comment it does in fact work, I was running the query without specifying the database I was working with in SQL management studio.

I marked your answer as helpful.

Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1