0
Next, I created a precedent that has two parameters Dt_inclusion and Dt_alteration, I would like to know how to insert(or if it is possible to use) a getdate to pick up the current date, instead of always having to manually type the as for example('2020-05-07')
Below is the run of the past.
EXEC [dbo].[sp_CRUDLogin]
@ID = 10,
@Usuario = N'Teste',
@Senha = N'123456',
@Nome = N'Teste',
@Email = N'[email protected]',
@Telefone = N'8002-4922',
@Dt_inclusao = '2020-05-07' <-- esse campo gostaria de utilizar um GETDATE no lugar da data especificada.
@Dt_alteracao = NULL,
@StatementType = N'Insert'
My previous :
ALTER PROCEDURE [dbo].[sp_CRUDLogin]
(
@ID integer,
@Usuario varchar(60),
@Senha varchar(60),
@Nome varchar(60),
@Email varchar(60),
@Telefone varchar(15),
@Dt_inclusao datetime,
@Dt_alteracao datetime,
@StatementType nvarchar(20)='')
AS
BEGIN
IF @StatementType='Insert'
BEGIN
INSERT INTO TbCADLogin
(ID,
Usuario,
Senha,
Nome,
Email,
Telefone,
Dt_inclusao,
Dt_alteracao)
VALUES (@ID,
@Usuario,
@Senha,
@Nome,
@Email,
@Telefone,
@Dt_inclusao,
@Dt_alteracao)
END
IF @StatementType='Select'
BEGIN
SELECT *
FROM TbCADLogin
END
IF @StatementType = 'Update'
BEGIN
UPDATE TbCADLogin
SET Usuario = @Usuario,
Senha = @Senha,
Nome = @Nome,
Email = @Email,
Telefone = @Telefone,
Dt_inclusao = @Dt_inclusao,
Dt_alteracao = @Dt_alteracao
WHERE ID = @ID
END
ELSE IF @StatementType='Delete'
begin
delete from TbCADLogin
where ID = @ID
END
END
Attempt to execute with GETDATE:
EXEC [dbo].[sp_CRUDLogin]
@ID = 10,
@Usuario = N'Teste',
@Senha = N'123456',
@Nome = N'Teste',
@Email = N'[email protected]',
@Telefone = N'8002-4922',
@Dt_inclusao = GETDATE, <--- GETDATE definido em vez do '2020-05-07'
@Dt_alteracao = NULL,
@StatementType = N'Insert'
When trying to use GETDATE I get the following result
"Msg 8114, Level 16, State 5, Procedure dbo.sp_CRUDLogin, Line 0 [Batch Start Line 0]
Erro ao converter tipo de dados nvarchar em date.
Completion time: 2020-05-07T15:22:07.2551684-03:00"
What should I do to make this project work, so that with only GETDATE I can get the current date and time when using the Internet?
Thanks in advance!