I am trying to insert value from select statement and i got error
我试图从select语句插入值,我得到错误
Syntax error in query expression 'Select C.ClientNo as ClientNo'
查询表达式中的语法错误'选择C.ClientNo作为ClientNo'
my query
我的疑问
Insert into [TempJobRecovery] (ClientNo,ClientName,TaxInvoiceNo,FeesforPS,TaxInvoiceDate,Partner,DeptNo,JobCode,TotalHour,TotalCost,Recovery,Status,PINO) Values
(Select C.ClientNo as ClientNo,
C.ClientName as ClientName,
C.taxinvoiceno as TaxInvoiceNo,
C.feesforps AS FeesforPS,
C.taxinvoicedte as TaxInvoiceDate,
C.Partner as Partner,
C.DeptNo as DeptNo,
C.JobCode as JobCode,
Sum(T.hrs) AS TotalHour,
Sum(T.hrs*T.corate) AS TotalCost,
(FeesforPS/TotalCost) as Recovery,
C.Status as Status,
C.PINO as PINO
FROM Clienttaxinvoice AS C
LEFT JOIN TimeSys AS T ON C.jobcode = T.jobcode
WHERE ((C.ClientNo)=[T].[cntno]) and C.Taxinvoicedte>=#01/31/2017# and C.Taxinvoicedte<=#01/31/2018#GROUP BY SerialNo,ClientNo,ClientName,TaxInvoiceNo,FeesforPS,C.taxinvoicedte,Partner,DeptNo,C.JobCode,Status,PINO)
What is wrong with my query? Pls let me known.
我的查询有什么问题?请让我知道。
1 个解决方案
#1
3
INSERT INTO
when used in conjunction with a SELECT
query does not use VALUES
. Rather, VALUES
is only used with inserting literal tuples of data. Try removing VALUES
:
INSERT INTO与SELECT查询结合使用时不使用VALUES。相反,VALUES仅用于插入文字元组数据。尝试删除VALUES:
INSERT INTO [TempJobRecovery] (ClientNo, ClientName, TaxInvoiceNo, FeesforPS,
TaxInvoiceDate, Partner, DeptNo, JobCode, TotalHour, TotalCost, Recovery,
Status, PINO)
SELECT
C.ClientNo,
C.ClientName,
C.taxinvoiceno,
C.feesforps,
C.taxinvoicedte,
C.Partner,
C.DeptNo,
C.JobCode,
SUM(T.hrs),
SUM(T.hrs*T.corate),
(FeesforPS / TotalCost),
C.Status,
C.PINO
FROM Clienttaxinvoice AS C
LEFT JOIN TimeSys AS T
ON C.jobcode = T.jobcode
WHERE
C.ClientNo = [T].[cntno] AND
C.Taxinvoicedte >= #01/31/2017# AND
C.Taxinvoicedte <= #01/31/2018#
GROUP BY
SerialNo,
ClientNo,
ClientName,
TaxInvoiceNo,
FeesforPS,
C.taxinvoicedte,
Partner,
DeptNo,
C.JobCode,
Status,
PINO
Note that I removed the aliases from the select statement above. There is no point to use aliases, because the column names are already fixed in the destination table for the insert.
请注意,我从上面的select语句中删除了别名。没有必要使用别名,因为列名已经固定在插入的目标表中。
#1
3
INSERT INTO
when used in conjunction with a SELECT
query does not use VALUES
. Rather, VALUES
is only used with inserting literal tuples of data. Try removing VALUES
:
INSERT INTO与SELECT查询结合使用时不使用VALUES。相反,VALUES仅用于插入文字元组数据。尝试删除VALUES:
INSERT INTO [TempJobRecovery] (ClientNo, ClientName, TaxInvoiceNo, FeesforPS,
TaxInvoiceDate, Partner, DeptNo, JobCode, TotalHour, TotalCost, Recovery,
Status, PINO)
SELECT
C.ClientNo,
C.ClientName,
C.taxinvoiceno,
C.feesforps,
C.taxinvoicedte,
C.Partner,
C.DeptNo,
C.JobCode,
SUM(T.hrs),
SUM(T.hrs*T.corate),
(FeesforPS / TotalCost),
C.Status,
C.PINO
FROM Clienttaxinvoice AS C
LEFT JOIN TimeSys AS T
ON C.jobcode = T.jobcode
WHERE
C.ClientNo = [T].[cntno] AND
C.Taxinvoicedte >= #01/31/2017# AND
C.Taxinvoicedte <= #01/31/2018#
GROUP BY
SerialNo,
ClientNo,
ClientName,
TaxInvoiceNo,
FeesforPS,
C.taxinvoicedte,
Partner,
DeptNo,
C.JobCode,
Status,
PINO
Note that I removed the aliases from the select statement above. There is no point to use aliases, because the column names are already fixed in the destination table for the insert.
请注意,我从上面的select语句中删除了别名。没有必要使用别名,因为列名已经固定在插入的目标表中。