I am getting the following error message with SQL Server 2005
Msg 120, Level 15, State 1, usp_AttributeActivitiesForDateRange procedure, line 18 The select list for the INSERT statement contains fewer elements than the insert list. The number of SELECT values must match the number of INSERT columns.
I have copy and paste a selection list and paste the list into excel and verified that each list has the same number of items. Both tables contain an additional primary key field that is not specified in the insert statement or in the select list. I'm not sure if this is relevant, but suspicious. Here is the source of my stored procedure:
CREATE PROCEDURE [dbo].[usp_AttributeActivitiesForDateRange]
(
@dtmFrom DATETIME,
@dtmTo DATETIME
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @dtmToWithTime DATETIME
SET @dtmToWithTime = DATEADD(hh, 23, DATEADD(mi, 59, DATEADD(s, 59, @dtmTo)));
INSERT INTO AttributedDoubleClickActivities
([Time],
[User-ID],
[IP],
[Advertiser-ID],
[Buy-ID],
[Ad-ID],
[Ad-Jumpto],
[Creative-ID],
[Creative-Version],
[Creative-Size-ID],
[Site-ID],
[Page-ID],
[Country-ID],
[State Province],
[Areacode],
[OS-ID],
[Domain-ID],
[Keyword],
[Local-User-ID],
[Activity-Type],
[Activity-Sub-Type],
[Quantity],
[Revenue],
[Transaction-ID],
[Other-Data],
Ordinal,
[Click-Time],
[Event-ID]) SELECT
[Time],
[User-ID],
[IP],
[Advertiser-ID],
[Buy-ID],
[Ad-ID],
[Ad-Jumpto],
[Creative-ID],
[Creative-Version],
[Creative-Size-ID],
[Site-ID],
[Page-ID],
[Country-ID],
[State Province],
[Areacode],
[OS-ID],
[Domain-ID],
[Keyword],
[Local-User-ID]
[Activity-Type],
[Activity-Sub-Type],
[Quantity],
[Revenue],
[Transaction-ID],
[Other-Data],
REPLACE(Ordinal, '?', '') AS Ordinal,
[Click-Time],
[Event-ID]
FROM Activity_Reports
WHERE [Time] BETWEEN @dtmFrom AND @dtmTo
AND REPLACE(Ordinal, '?', '') IN
(SELECT REPLACE(Ordinal, '?', '') FROM Activity_Reports
WHERE [Time] BETWEEN @dtmFrom AND @dtmTo
EXCEPT
SELECT CONVERT(VARCHAR, TripID) FROM VisualSciencesActivities
WHERE [Time] BETWEEN @dtmFrom AND @dtmTo);
END
GO