我有一个TimeSheet
表,并希望在asp.net中通过从Employee表和当前日期插入ID时默认值插入默认值,默认值为1,但是我收到错误:
Msg 102,Level 15,State 1,Line 1
','附近的语法不正确。
代码:
create PROCEDURE [dbo].[sp_TimeSheet_Init]
@EmpID int,
@TimeCheckDate datetime,
@Day1 int,@Day2 int,@Day3 int,@Day4 int,@Day5 int,
@Day6 int,@Day7 int,@Day8 int,@Day9 int,@Day10 int,
@Day11 int,@Day12 int,@Day13 int,@Day14 int,@Day15 int,
@Day16 int,@Day17 int,@Day18 int,@Day19 int,@Day20 int,
@Day21 int,@Day22 int,@Day23 int,@Day24 int,@Day25 int,
@Day26 int,@Day27 int,@Day28 int,@Day29 int,@Day30 int,
@Day31 int
AS
INSERT INTO [TimeSheet]([EmpID], [TimeCheckDate], [Day1], [Day2], [Day3], [Day4], [Day5], [Day6], [Day7], [Day8], [Day9], [Day10], [Day11],[Day12], [Day13], [Day14], [Day15], [Day16], [Day17], [Day18], [Day19], [Day20],[Day21], [Day22], [Day23], [Day24], [Day25], [Day26], [Day27], [Day28], [Day29],[Day30], [Day31])
SELECT
Id
FROM
Employee
WHERE
WorkingStatusId = '1', getdate(), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
此查询没问题:
select Id
from Employee
where WorkingStatusId = '1'
答案 0 :(得分:1)
基本上,你应该分开
Timesheet
一个月的基本信息 - 这包含EmployeeID
,月份和年份以及整整一个月所需的其他信息
将每日信息放入一个单独的表格TimesheetDay
,其中包含每天的信息;诸如日期编号(1-31),价值(工作小时数)等等 - 并且它与给定月份的Timesheet
条目相关联
不要重复任何数据!您不要在每个EmployeeID
条目上都需要TimesheetDay
- 已关联的Timesheet
行已包含该信息。
这是基本的数据库设计101 - 你的表应该是这样的:
这将是创建这两个表及其约束的脚本:
CREATE TABLE [dbo].[Timesheet]
(
[TimeSheetID] [int] NOT NULL,
[EmployeeID] [int] NOT NULL,
[TimesheetMonth] [int] NOT NULL,
[TimesheetYear] [int] NOT NULL,
CONSTRAINT [PK_Timesheet]
PRIMARY KEY CLUSTERED ([TimeSheetID] ASC)
)
CREATE TABLE [dbo].[TimesheetDay]
(
[TimesheetDayID] [int] NOT NULL,
[TimesheetID] [int] NOT NULL,
[DayNumber] [int] NOT NULL,
[DayValue] [decimal](15, 2) NOT NULL,
CONSTRAINT [PK_TimesheetDay]
PRIMARY KEY CLUSTERED ([TimesheetDayID] ASC)
)
GO
ALTER TABLE [dbo].[TimesheetDay]
ADD CONSTRAINT [DF_TimesheetDay_DayValue]
DEFAULT ((8.0)) FOR [DayValue]
ALTER TABLE [dbo].[TimesheetDay] WITH CHECK
ADD CONSTRAINT [FK_TimesheetDay_Timesheet]
FOREIGN KEY([TimesheetID])
REFERENCES [dbo].[Timesheet] ([TimeSheetID])
ALTER TABLE [dbo].[TimesheetDay]
CHECK CONSTRAINT [FK_TimesheetDay_Timesheet]
GO
答案 1 :(得分:0)
create PROCEDURE [dbo].[sp_TimeSheet_Init]
@EmpID int,
@TimeCheckDate datetime,
@Day1 int,@Day2 int,@Day3 int,@Day4 int,@Day5 int,
@Day6 int,@Day7 int,@Day8 int,@Day9 int,@Day10 int,
@Day11 int,@Day12 int,@Day13 int,@Day14 int,@Day15 int,
@Day16 int,@Day17 int,@Day18 int,@Day19 int,@Day20 int,
@Day21 int,@Day22 int,@Day23 int,@Day24 int,@Day25 int,
@Day26 int,@Day27 int,@Day28 int,@Day29 int,@Day30 int,
@Day31 int
AS
INSERT INTO [TimeSheet]([EmpID],[TimeCheckDate],[Day1],[Day2],[Day3],[Day4],[Day5],[Day6],[Day7],
[Day8],[Day9],[Day10],[Day11],[Day12],[Day13],[Day14],[Day15],
[Day16],[Day17],[Day18],[Day19],[Day20],[Day21],[Day22],[Day23],
[Day24],[Day25],[Day26],[Day27],[Day28],[Day29],[Day30],[Day31])
select Id ,getdate(),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
from Employee where WorkingStatusId='1'