使用具有一些硬编码值的两个表的值在SQL中创建表

使用具有一些硬编码值的两个表的值在SQL中创建表

问题描述:

使用带有一些硬编码值的两个表的值在SQL中创建一个表。

i想为每个employee_code插入punchin和puchout,我将从[AttendanceCorrection]中获取。[dbo]。[来自[Zultime]的Tbl_FMOEmp]和Punch_Date。[dbo]。[TIME_SHEET]



我尝试了什么:



INSERT INTO Tbl_EmpNotPunching

选择

(SELECT [employee_Code] FROM [AttendanceCorrection]。[dbo]。[Tbl_FMOEmp])as employee_Code ,

(选择不同[Punch_Date] FROM [Zultime]。[dbo]。[TIME_SHEET])作为Punch_Date,

'7:30'作为PunchIN,

'16:30'作为打击

creating a table in SQL using values of two table with some hard coded values.
i want to insert punchin and puchout for each employee_code which i will get from [AttendanceCorrection].[dbo].[Tbl_FMOEmp] and Punch_Date from [Zultime].[dbo].[TIME_SHEET]

What I have tried:

INSERT INTO Tbl_EmpNotPunching
select
(SELECT [employee_Code] FROM [AttendanceCorrection].[dbo].[Tbl_FMOEmp]) as employee_Code,
(SELECT distinct [Punch_Date] FROM [Zultime].[dbo].[TIME_SHEET]) as Punch_Date,
'7:30' as PunchIN,
'16:30' as punchOUT

感谢大家的宝贵时间和精力,我得到了答案....

声明@P_Date表



[P_Date]日期



插入@P_Date选择distinct [P_Date]

FROM [Zultime]。[dbo]。[TIME_SHEET] INSERT INTO Tbl_EmpNotPunching

s选择[Pin_Code],P_Date,'07:30'作为PunchIN,'16:30'作为打孔

来自[AttendanceCorrection]。[dbo]。[Tbl_FMOEmp]

交叉加入@P_Date
Thanks everyone for your valuable time and effort i got my answer....
declare @P_Date table
(
[P_Date] date
)
insert into @P_Date select distinct [P_Date]
FROM [Zultime].[dbo].[TIME_SHEET] INSERT INTO Tbl_EmpNotPunching
select [Pin_Code], P_Date, '07:30' as PunchIN, '16:30' as punchOUT
FROM [AttendanceCorrection].[dbo].[Tbl_FMOEmp]
cross join @P_Date