我可以在以下语句中将此getdate()
调用放在哪里:
CREATE PROCEDURE sp_test
(@email nvarchar(50), @password nvarchar(50))
AS
SELECT employee_id, position
FROM tbl_employee_tbl
WHERE email = @email AND login_password = @password
INSERT INTO tbl_log_activity(employee_id, sign_in_time)
SELECT
employee_id
FROM
tbl_employee_tbl,getdate()
WHERE
email = @email
答案 0 :(得分:3)
以这种方式更改第二个语句:
INSERT INTO tbl_log_activity(employee_id,sign_in_time)
SELECT employee_id, Getdate()
FROM tbl_employee_tbl
WHERE email=@email
答案 1 :(得分:1)
create procedure
sp_test(@email nvarchar(50),@password nvarchar(50))
as
select
employee_id,
position
from
tbl_employee_tbl
where
email=@email and login_password= @password
insert into
tbl_log_activity(employee_id,sign_in_time)
select
employee_id
,getdate()
from
tbl_employee_tbl
where email=@email
答案 2 :(得分:0)
你可以试试这个:
FORMAT()
函数在SQL Server 2008中不起作用,因此您可以使用CONVERT()
。
ALTER procedure [dbo].[sp_test]
(
@email nvarchar(50),
@password nvarchar(50)
)
as
select employee_id,position
from tbl_employee_tbl
where email=@email and login_password= @password
insert into tbl_log_activity(employee_id,sign_in_time)
select employee_id,convert(varchar(25), GETDATE(),131) as date
from tbl_employee_tbl
where email=@email
注意:但我建议您不要在数据库中存储任何格式的日期。将其存储为日期时间,只要您希望访问该值,就可以在选择查询中对其进行格式化,并根据需要进行显示。
如果你想在db中存储具有特定格式的日期,请确保你有sign_in_time列为varchar(25)。
答案 3 :(得分:0)
像这样更改代码
CREATE PROCEDURE sp_test
(@email nvarchar(50), @password nvarchar(50))
AS
SELECT employee_id, position
FROM tbl_employee_tbl
WHERE email = @email AND login_password = @password
INSERT INTO tbl_log_activity(employee_id, sign_in_time)
SELECT
employee_id ,getdate()
FROM
tbl_employee_tbl
WHERE
email = @email