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 2008 Forums
 Other SQL Server 2008 Topics
 INSERT Statement

Author  Topic 

sweetpepper66
Starting Member

10 Posts

Posted - 2011-10-15 : 10:49:01
Hi,
Need some help to know what did I do wrong with my query....It is a little frustrating since I am new to SQL. I have to write an INSERT statement that adds a row to the VendorCopy table for each non-California vendor in the Vendors table. (this will result in duplicate vendors in the VendorCopy)
So far I have this below, but get an error. Do I have to use the SELECT and FROM statement also?

INSERT INTO VendorCopy (VendorState)
VALUES ('CA', 'non-California')

Any suggestions would be really appreciate.... Thanks


Frederique

Cindyaz
Yak Posting Veteran

73 Posts

Posted - 2011-10-15 : 11:56:35
select * into vendorcopy
from vendors

This will create a table vendorcopy and will copy all data from vendors to vendorcopy.

If vendorcopy table exists, use Insert into
insert into vendorcopy(<column list separated by comma>) select <column list separated by comma> from vendors

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-15 : 12:40:59
what you did wrong was specifying additional values in insert. you've given only one column and passed two values.

As Cindyaz specifies you need a INSERT SELECT
which column in your vendor table designate its non california?


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sweetpepper66
Starting Member

10 Posts

Posted - 2011-10-15 : 14:27:21
Thanks to both of you, I really appreciate it. Visakh16 you are absolutely right, I gave one column and passed two values....
With the syntax INSERT, I am having hard time. Gonna have to work on that one. I can write an UPDATE statement but not an INSERT statement...... "so not right"
Cindyaz thanks, I had already created the VendorCopy table few questions back.
Go to Top of Page
   

- Advertisement -