Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert across joined tables

Author  Topic 

conorpboland
Starting Member

1 Post

Posted - 2009-07-21 : 06:45:11
Hi. I have two tables

HostNameTable
Host ID PK
HostName

LogTable
Log ID PK auto Increment
HostID FK
Message

I need to do an insert onto the Log Table and reference the HostID of the HostTable that corresponds to the Name of the host.

Insert into LotTable (HostID, Message) values (select hsotid from hosttable where hostname = @host, "message string") does not work as a statement.

I am using TSQL

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-21 : 06:52:39
insert into lottable (hostid,message)
select hostid,'message string' from hosttable where hostname = @host
Go to Top of Page
   

- Advertisement -