我插入值到表像下面加入工作不正常
INSERT INTO p_leave_allocation_11122015(Mkey, Entry_Sr_no, Comp_mkey,FDepartment_Id,FModule_Id,Year, Emp_mkey, Emp_card_no, U_Datetime, Delete_Flag,Month12,PL_Days,)
SELECT
ROW_NUMBER() OVER(ORDER BY p_leave_allocation.MKey) + 1643,
ROW_NUMBER() OVER(ORDER BY Entry_Sr_no) + 898,
Comp_mkey, FDepartment_Id, FModule_Id,
'2016', Emp_mkey, Emp_card_no, U_Datetime,
Delete_Flag, Month12, 0
FROM
p_leave_allocation lev
WHERE
Emp_mst Emp
LEFT JOIN
p_leave_allocation AND Emp.status IN ('A','S')
AND YEAR(Emp.Date_Of_Joining) = '2015'
,但我得到一個錯誤:
An expression of non-boolean type specified in a context where a condition is expected, near 'Emp'.
這裏有什麼問題?
UPDATE
我想這樣的,但得到錯誤的
Incorrect syntax near the keyword 'WHERE'.
代碼爲: -
INSERT INTO p_leave_allocation_11122015(Mkey, Entry_Sr_no, Comp_mkey,FDepartment_Id,FModule_Id,Year, Emp_mkey, Emp_card_no, U_Datetime, Delete_Flag,Month12,PL_Days,)
SELECT
ROW_NUMBER() OVER(ORDER BY p_leave_allocation.MKey) + 1643,
ROW_NUMBER() OVER(ORDER BY Entry_Sr_no) + 898,
Comp_mkey, FDepartment_Id, FModule_Id,
'2016', Emp_mkey, Emp_card_no, U_Datetime,
Delete_Flag, Month12, 0
FROM
p_leave_allocation lev LEFT JOIN Emp_mst emp
WHERE
emp.Status in ('A','S')
and
Year(emp.Date_Of_Joining) = '2015'
格式化您的問題,使其可讀 – Amit
@Amit是downvote的原因嗎? – BNN
它應該是'SELECT ... FROM ... LEFT JOIN .... WHERE .....'你正在混淆T-SQL語法 - 你應該去查看如何編寫的細節SQL Server聯機叢書上正確的'SELECT'語句! –