This is my stored procedure:
ALTER PROCEDURE [dbo].[Addentry](
@entHead VARCHAR(50) = NULL,
@entBody VARCHAR(2000) = NULL,
@entType SYSNAME,
@entuID INT = 0)
AS
BEGIN
SET @entType = Rtrim(@entType)
SET @entuID = Rtrim(@entuID)
DECLARE @cmd AS NVARCHAR(MAX)
SET @cmd = N'INSERT INTO ' + Quotename(@entType) + N' (uID, Heading, Body, pTime) VALUES ' + (@entuID + ', ' + @entHead + ', ' + @entBody + ', ' + Getutcdate())
EXEC Sp_executesql
@cmd
IF @@ERROR <> 0
RAISERROR ('Post was not added',16,1)
END
RETURN
The error I get is this: Conversion failed when converting datetime from character string
I guess it has something to do with turning the getutcdate() into a string and then back to datetime. Is there another way around this?
Any suggestions?
Sincerely
Niklas Kihl