我正在尝试将临时表中的值插入到另一个表中,并且它给出了语法错误。我不确定我错过了什么。错误在选择语句
上INSERT INTO Reimbursement_EBSUtilization (PRR_Id, SD_Id, ServiceMonth, StandardUnits,
UnitsDelivered, Rate, BHFormName, LastChgDate, LastChgUserId)
SELECT (
83, serviceid, 2016/03/01, StandardUnits,
null, Rate, BHFormsName, getdate(), 'vpanaka')
FROM
@temp
答案 0 :(得分:4)
在日期周围加上单引号并删除所有列周围的括号:
INSERT INTO Reimbursement_EBSUtilization(PRR_Id, SD_Id, ServiceMonth,
StandardUnits, UnitsDelivered, Rate, BHFormName,
LastChgDate, LastChgUserId)
select 83, serviceid, '2016-03-01', -- Hyphens are the ISO 8601 standard
StandardUnits, null, Rate, BHFormsName,
getdate(), 'vpanaka'
from @temp t;
我建议你使用LastChgDate
和LastChgUserId
的默认值,这样就不必在输入时设置它们了:
LastChgDate datetime default getdate(), -- or `datetime2` if you prefer
LastChgUserId sysname default @@system_user -- I think this is what you want for the user
答案 1 :(得分:2)
括号正在打破SQL。它不是有效的格式/模式。
select(
83,
serviceid,
2016/03/01,
StandardUnits,
null,
Rate,
BHFormsName,
getdate(),
'vpanaka')
from @temp
应该是
select
83,
serviceid,
'2016/03/01',
StandardUnits,
null,
Rate,
BHFormsName,
getdate(),
'vpanaka'
from @temp