标量函数取规则名称
USE [test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER function [dbo].[GetNameList](@Ruleids nvarchar(MAX)) returns nvarchar(MAX) as begin declare @str2 nvarchar(MAX) set @str2='' set @RuleGids=ltrim(@Ruleids) set @RuleGids=rtrim(@Ruleids) if(len(@Ruleids)>0) begin select @str2=@str2+ a.RuleName +'|' from TestRule (nolock) as a inner join TestDetailRule (nolock) as b on a.id=b.Ruleid where b.id in(select id from Split(@Ruleids,',')) if(len(@str2)>0) begin set @str2=SUBSTRING(@str2,0,len(@str2)); end end return @str2 End USE [test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER function [dbo].[split](@SourceSql varchar(8000),@StrSeprate varchar(10)) returns @temp table(id Nvarchar(100)) as begin declare @i int set @SourceSql=rtrim(ltrim(@SourceSql)) set @i=charindex(@StrSeprate,@SourceSql) while @i>=1 begin insert @temp values(left(@SourceSql,@i-1)) set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i) set @i=charindex(@StrSeprate,@SourceSql) end if @SourceSql<>'\' insert @temp values(@SourceSql) return end
select Convert(varchar(10), DATEADD(M,-1 ,DATEADD(DD,-DAY(GETDATE())+1,GETDATE())),23)
select
CONVERT(varchar(10), DATEADD(DAY,-1,dateadd(m,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))),23)+' 23:59:59.999'
select CONVERT(VarChar(7), YEAR(DATEADD(MONTH,-1,GETDATE())), 120)+'-'+ CONVERT(VarChar(7), RIGHT('00'+CAST(MONTH(DATEADD(MONTH,-1, GETDATE())) AS VARCHAR(2)),2), 120)
select CONVERT(VarChar(7), CONVERT(varchar(10), DATEADD(DAY,-1,dateadd(m,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))),23)+' 23:59:59.999', 120)