Situatie
Pentru ca uneori avem nevoie sa verificam daca o data calendaristica este sau nu ultima zi din luna, am creat o functie care verifica acest lucru. (In ea se apeleaza o alta functie care transforma data intr-un format fara minute si secunde)
Solutie
create function dbo.BD_TransfDate
(@Data datetime)
returns datetime
as
BEGIN
return convert(datetime, convert(varchar, @Data, 112), 112)
END
——————————-
CREATE FUNCTION [dbo].[BD_IsEOM](@Data datetime)
returns bit
as
BEGIN
declare @DataEOM datetime
set @DataEOM = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@Data)+1,0))
set @DataEOM = dbo.BD_TransfDate(@DataEOM)
set @Data = dbo.BD_TransfDate(@Data)
if @Data = @DataEOM
return 1
return 0
END
Leave A Comment?