简体   繁体   中英

SQL Insert into giving Invalid column error

Trying to execute the following SQL but gives invalid column "open" etc for all columns

    insert into t ("Date","assignee","pkey","open","In Progress","Awaiting  Release","Referred")
select date, assignee,pkey,open,[In Progress],[Awaiting Release],[referred] from (
SELECT Cast(Getdate() AS DATE) AS Date, 
       pname                   AS Status, 
       assignee, 
       pkey 
FROM   s JI, 
       k JS 
WHERE  JI.issuestatus = JS.id 
       AND JI.issuetype IN ( 21, 4 ) 
       AND JS.pname IN( 'Open', 'In Progress', 'Awaiting Release', 'Referred' ))as source
    PIVOT
    (count([Status])
    FOR [status] in ([Open],[In Progress],[Awaiting Release],[Referred])) as pvt

不确定,但如下更新第一条语句是可行的

insert into t ([Date],[assignee],[pkey],[open],[In Progress],[Awaiting  Release],[Referred])

OPEN is a command so you need to put square brackets around it to highlight it is a field

 insert into t ("Date","assignee","pkey","open","In Progress","Awaiting  Release","Referred")
select date, assignee,pkey,[open],[In Progress],[Awaiting Release],[referred] from (
SELECT Cast(Getdate() AS DATE) AS Date, 
       pname                   AS Status, 
       assignee, 
       pkey 
FROM   s JI, 
       k JS 
WHERE  JI.issuestatus = JS.id 
       AND JI.issuetype IN ( 21, 4 ) 
       AND JS.pname IN( 'Open', 'In Progress', 'Awaiting Release', 'Referred' ))as source
    PIVOT
    (count([Status])
    FOR [status] in ([Open],[In Progress],[Awaiting Release],[Referred])) as pvt

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