为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:7
【操作系统】:
【CPU】:
【问题描述】*:sql server上创建的标量函数 怎么完美在达梦上创建一模一样的
附原sql语句
USE [模式名]
GO
/****** Object: UserDefinedFunction [dbo].[SplitDay] Script Date: 02/28/2022 15:15:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[SplitDay]
(
@StartDate DateTime,
@EndDate DateTime,
@iDay numeric(16,1),
@iRealDay numeric(16,1),
@bALL INT,
@SFDate DateTime,
@STDate DateTime
)
RETURNS numeric(16,1)
AS
BEGIN
declare @iNum numeric(16,1)
declare @iSysID BigInt
declare @nowDay DateTime
declare @cWeekName nvarchar(20)
set @iNum=0
set @StartDate= CONVERT(varchar(10),@StartDate,120)
if @iRealDay=0
begin
set @iRealDay =@iDay
end
set @SFDate=CONVERT(varchar(10),@SFDate,120)
set @STDate=CONVERT(varchar(10),@STDate,120)
if @EndDate='' or @EndDate IS NULL
begin
set @EndDate=@STDate
end
set @iSysID=ISNULL((Select ID From Sysobjects where xtype='U' and name='SetHoliDay'),0)
if @iSysID =0
begin
set @nowDay=@StartDate
if @nowDay <@SFDate
begin
set @nowDay =@SFDate
end
if @EndDate>@STDate
begin
set @EndDate =@STDate
end
while CONVERT(nvarchar(10),@nowDay,120)<=Convert(varchar(10),@EndDate,120)
begin
if CONVERT(nvarchar(10),@nowDay,120) >=CONVERT(nvarchar(10),@SFDate,120) and CONVERT(nvarchar(10),@nowDay,120) <=CONVERT(nvarchar(10),@STDate,120)
begin
if @bALL =0
begin
set @cWeekName =(Select DATENAME(weekday,''+CONVERT(nvarchar(10),@nowDay,120)+''))
if @cWeekName ='星期六' or @cWeekName ='星期日'
begin
set @iNum=@iNum
end
else
begin
set @iNum=@iNum + 1
end
end
else
begin
set @iNum=@iNum + 1
end
end
if @iNum >@iRealDay
begin
set @iNum =@iRealDay
return @iNum
end
set @nowDay=@nowDay +1
end
end
else
begin
set @nowDay=@StartDate
if @nowDay <@SFDate
begin
set @nowDay =@SFDate
end
if @EndDate>@STDate
begin
set @EndDate =@STDate
end
while CONVERT(nvarchar(10),@nowDay,120)<=Convert(varchar(10),@EndDate,120)
begin
if CONVERT(nvarchar(10),@nowDay,120) >=CONVERT(nvarchar(10),@SFDate,120) and CONVERT(nvarchar(10),@nowDay,120) <=CONVERT(nvarchar(10),@STDate,120)
begin
if @bALL =0
begin
set @cWeekName=ISNULL((Select Top 1 ISNULL(DDATE,'') as cStrDate From FE_BASE5..SetHoliDay where dDate=''+CONVERT(nvarchar(10),@nowDay,120)+''),'')
if @cWeekName<>''
begin
set @iNum=@iNum
end
else
begin
set @iNum=@iNum +1
end
end
else
begin
set @iNum=@iNum + 1
end
end
if @iNum >@iRealDay
begin
set @iNum =@iRealDay
return @iNum
end
set @nowDay=@nowDay +1
end
end
begin
if @iNum >@iRealDay
begin
set @iNum =@iRealDay
end
end
return @iNum
END
大佬,这个标量函数的问题解决没,我也遇到同样的问题了,求教!
https://eco.dameng.com/docs/zh-cn/start/migrate-sqlserver-dm.html
请参考一下这个文档,里面有个手册可以下载