简体   繁体   中英

can anyone tell me whats wrong with this insert statement?

the statement is,

INSERT INTO int_in_sales_cosmic_hdr
            ([sales_id],
             [description],
             [create_date],
             [update_date],
             [user_id],
             [start_date],
             [period_week],
             [action],
             [is_forecast])
SELECT DISTINCT Cast(Datepart(year, [create_date])AS NVARCHAR(10))
                + Cast(Datepart(week, [create_date])AS NVARCHAR(10)),
                [description],
                [create_date],
                Getdate(),
                CURRENT_USER(),
                [start_date],
                [period_week],
                [action],
                [is_forecast]
FROM   #temp_sales  

the error is,

Msg 120, Level 15, State 1, Procedure CDG_LoadData, Line 1641 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.

the insert and select contains same number of columns.

You need to remove parenthesis from CURRENT_USER . Current_User is not a inbuilt function. It

Returns the name of the current user

 INSERT INTO int_in_sales_cosmic_hdr
            ([sales_id],
             [description],
             [create_date],
             [update_date],
             [user_id],
             [start_date],
             [period_week],
             [action],
             [is_forecast])
SELECT DISTINCT Cast(Datepart(year, [create_date])AS NVARCHAR(10))
                + Cast(Datepart(week, [create_date])AS NVARCHAR(10)),
                [description],
                [create_date],
                Getdate(),
                CURRENT_USER,
                [start_date],
                [period_week],
                [action],
                [is_forecast]
FROM   #temp_sales  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM