SQL Server中的INSERT语句 - 是否正确?

时间:2013-01-30 13:17:07

标签: sql sql-server

insert into Employee_Document 
values(FristName, LastName, BeginWeek, EndWeek, 
       Hrs_Mon, hrs_tues, Hrs_Wed, Hrs_Thu, Hrs_Fri, Total_Hours,
       TaskDesc_Mon, TaskDesc_Tues, TaskDesc_Wed, TaskDesc_Thu, TaskDesc_Fri, '')

select 
   FristName, LastName, BeginWeek, EndWeek, 
   TotalHours where TimeSheetDate='31-12-2012' AS Hrs_Mon,'08:00:00',
   TotalHours where TimeSheetDate='02-01-2013' AS Hrs_Wed,
   TotalHours where TimeSheetDate='03-01-2013' AS Hrs_Thu,
   TotalHours where TimeSheetDate='04-01-2013' AS Hrs_Fri,
   TaskDescription where TimeSheetDate='31-12-2012' AS TaskDesc_Mon,
   TaskDescription where TimeSheetDate='02-01-2013' AS TaskDesc_Wed,
   TaskDescription where TimeSheetDate='03-01-2013' AS TaskDesc_Thu,
   TaskDescription where TimeSheetDate='04-01-2013' AS TaskDesc_Fri,'' 
from 
   vw_TSDailyTotalHoursTaskDesc)

这句话是否有任何错误,因为我是SQL Server新手。

提前致谢。

2 个答案:

答案 0 :(得分:0)

(LOL)

好的,首先需要删除关键字VALUES,基本插入语法是:

INSERT [INTO] tablename (column list...) VALUES (literals...)

INSERT [INTO] tablename (column list) SELECT...

如上所述,只需删除VALUES即可。

接下来,不存在这样一个名为''的列,不能(如果真的有反复的话,可以['']限制],排除它。

最后,我猜你正在尝试用这个

做什么
TotalHours where TimeSheetDate='31-12-2012' AS Hrs_Mon,'08:00:00',

可能就像

CASE WHEN TimeSheetDate='31-12-2012' THEN TotalHours ELSE '08:00:00' END AS Hrs_Mon,

或者什么?

答案 1 :(得分:-2)

据我所知,唯一不正确的是在第一行你有不需要的单词值。