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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Customized Insert Into

Author  Topic 

WindChaser
Posting Yak Master

225 Posts

Posted - 2009-09-17 : 13:45:36
Hi folks. I know that there are 2 basic ways of inserting data in a table:

INSERT INTO MyTable (PriKey, Description)
VALUES (123, 'A description of part 123.')

or

INSERT INTO MyTable  (PriKey, Description)
SELECT ForeignKey, Description
FROM SomeView


I'd like to know if there is any way of combining the 2 ways in one single insert statement such as:

INSERT INTO MyTable  (PriKey, Description)
((SELECT ForeignKey
FROM SomeView), 'My custom description'))


I tried playing with the above with no success.



TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-17 : 13:47:47
insert into mytable (priKey, description)
select foreign key, 'My custom description' from SomeVew

Be One with the Optimizer
TG
Go to Top of Page

WindChaser
Posting Yak Master

225 Posts

Posted - 2009-09-17 : 14:12:11
Oh for cryin' out loud. Thanks for bearing with my ignorance TG. It was too elegantly simple for my small head. Thanks!!!
Go to Top of Page
   

- Advertisement -