?
Solved

What's wrong with this insert statement?

Posted on 2008-11-07
4
Medium Priority
?
130 Views
Last Modified: 2012-05-05
I keep getting this error:
The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.

Table1 that i'm inserting into has 17 columns. Table2 that i'm reading from has 3 columns.
I keep counting and the insert and select parameters match,,,
what am I missing?
Insert into dbo.Table1  (ID,
                                   CreatedOn,
                                   UpdatedOn,
                                   ModifiedBy,
                                   RowVersion,
                                   LocaleID,
                                   ProcessorId,
                                   IsActive,
                                   Code,
								   Description,
                                   FromName,
                                   FromEmailAddress,
                                   ToName,
                                   ToEmailAddress,
                                   Subject,
                                   TextBody,
                                   HtmlBody)
select NewID(),
       getdate(),
       getdate(),
       null,
       (select @@DBTS) as RowVersion,
       1031,
       id,
       0,
       'Ship',
       'Sent email.',
       'Customer service,
       'test@test.com',
       '{Customer.FirstName} {Customer.LastName}',
       '{Customer.EmailAddress}',
       'Ship Confirmation for Order #{Number}',
       'Text Body ship - text goes here'
       'HTML Body ship - text goes here'
 
  from Table2
where [name] = 'XY123'

Open in new window

0
Comment
Question by:Camillia
  • 2
4 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 22905247
can
'Text Body ship - text goes here'
'HTML Body ship - text goes here'
fields can contain single quotation mark...
0
 
LVL 16

Expert Comment

by:brad2575
ID: 22905252
change this:

select NewID(),
       getdate(),
       getdate(),
       null,
       (select @@DBTS) as RowVersion,
       1031,
       id,
       0,
       'Ship',
       'Sent email.',
       'Customer service,
       'test@test.com',
       '{Customer.FirstName} {Customer.LastName}',
       '{Customer.EmailAddress}',
       'Ship Confirmation for Order #{Number}',
       'Text Body ship - text goes here'
       'HTML Body ship - text goes here'


to this:

select NewID(),
       getdate(),
       getdate(),
       null,
       (select @@DBTS) as RowVersion,
       1031,
       id,
       0,
       'Ship',
       'Sent email.',
       'Customer service,
       'test@test.com',
      Customer.FirstName + ' ' + Customer.LastName,
       'Customer.EmailAddress',
       'Ship Confirmation for Order #' + Number,
       'Text Body ship - text goes here'
       'HTML Body ship - text goes here'
0
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 total points
ID: 22905260
as I see you have forgetten to put a ',' ofter the
'Text Body ship - text goes here'
line
0
 
LVL 7

Author Comment

by:Camillia
ID: 22905279
tigin44, just noticed the missing comma, let me try
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question