SQL Server INSERT … SELECT Statement won't parse

前端 未结 5 1575
生来不讨喜
生来不讨喜 2021-01-14 04:55

I am getting the following error message with SQL Server 2005

Msg 120, Level 15, State 1, Procedure usp_AttributeActivitiesForDateRange, Line 18 The

相关标签:
5条回答
  • 2021-01-14 05:12

    You don't have enough fields in your select list for the insert statement you gave.

    0 讨论(0)
  • 2021-01-14 05:15

    You're missing a comma here:

    [Local-User-ID] [Activity-Type]
    

    Should be:

    [Local-User-ID], [Activity-Type]
    
    0 讨论(0)
  • 2021-01-14 05:24

    You are missing a comma between [Local-User-ID] and [Activity-Type].

    Try:

    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); 
    
    0 讨论(0)
  • 2021-01-14 05:27

    In the Select there is a typo

    [Local-User-ID]
                [Activity-Type],
    

    you are missing ","!

    0 讨论(0)
  • 2021-01-14 05:28

    you forgot a comma after [Local-User-ID] so it aliased that column as [Activity-Type]

    common mistake

    in essence you have Local-User-ID] AS [Activity-Type], the AS is optional

    0 讨论(0)
提交回复
热议问题