Luis Diaz
asked on
SQL: display get date in a @variable
Hello experts,
I call the following .sql through a SQLCMD.
I would like to add at the beginning of @message getdate with with the following format: 2018-06-15 23:54:42.013
SET @vMessage = getdate () + ':
How should I proceed?
If you have questions, please contact me.
I call the following .sql through a SQLCMD.
DECLARE @vThreshold_PRC NUMERIC(18,2) = $(V_THRESHOLD_PRC),
@vCurr_PRC NUMERIC(18,2),
@vMessage NVARCHAR(500),
@vCpt_sync INT,
@vCpt_all INT
BEGIN
SELECT @vCurr_PRC = CAST(100.00 * (cpt_sync / cpt_all ) AS numeric(18,2)), @vCpt_sync = cpt_sync, @vCpt_all = cpt_all
FROM (SELECT COUNT(*) * 1.00 cpt_sync FROM $(V_LNKSERVER)[$(V_DBNAME)].[$(V_SCHNAME)].[$(V_TBLNAME)]) S,
(SELECT COUNT(*) * 1.00 cpt_all FROM $(V_LNKSERVER)[$(V_DBNAME)].[$(V_SCHNAME)].[$(V_TBLNAME)_INTERNAL]) I
IF @vCurr_PRC > @vThreshold_PRC
BEGIN
SET @vMessage = ': Le nombre de projets a transmettre (' + CAST(COALESCE(@vCpt_sync, 0) AS NVARCHAR(50)) +
') sur un total de ' + CAST(COALESCE(@vCpt_all, 0) AS NVARCHAR(50)) + ' projets, est superieur au pourcentage de projets maximum pouvant etre transmis (' +
CAST(COALESCE(@vThreshold_PRC, 0) AS NVARCHAR(50)) + ') : pourcentage courant calcule = ' + CAST(COALESCE(@vCurr_PRC, 0) AS NVARCHAR(50))
--PRINT @vMessage
RAISERROR(@vMessage,16,1)
END
END
GO
I would like to add at the beginning of @message getdate with with the following format: 2018-06-15 23:54:42.013
SET @vMessage = getdate () + ':
How should I proceed?
If you have questions, please contact me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Yes, John is right. You need to use Style 121 to convert it into your desired form.
Regards,
Pratik
Yes, John is right. You need to use Style 121 to convert it into your desired form.
Regards,
Pratik
ASKER
Thank you, John Vidmar proposal works.
Open in new window