• 行列转换


    CREATE proc [dbo].[R_Parities_Config_CurrencyExchangeRate_V2]
        @FromCode nvarchar(400),
        @ToCode nvarchar(400),
        @EffectiveDate nvarchar(400),
        @ChangeDate nvarchar(400)
        as
        begin
            SET NOCOUNT ON;
            select f.col as FromCode into #FromTable from (select distinct col from dbo.[Split](@FromCode, ',')) as f
                where f.col in (select distinct FromCode from Config_CurrencyExchangeRate where ToCode = @ToCode and FromCode != @ToCode)
            select * into #ToTable from Config_CurrencyExchangeRate
                where ToCode = @ToCode and EffectiveDate >=@EffectiveDate and EffectiveDate <=@ChangeDate
            
            select a.EffectiveDate,c.FromCode+'/'+a.ToCode as CurrencyType,a.Rate into #a from #ToTable as a
            right join #FromTable as c on c.FromCode = a.FromCode order by a.EffectiveDate desc
     
        declare @groupField varchar(1000)
      select @groupField=isnull(@groupField,'')+case when isnull(@groupField,'')='' then '' else ',' end+QUOTENAME(CurrencyType)
      from (select rtrim(CurrencyType) as CurrencyType from (select distinct CurrencyType from #a) as a )t  
      declare @sql nvarchar(4000)
      set @sql=N'
      select *
      from
            (select  EffectiveDate,rtrim(CurrencyType) as CurrencyType,
       MAX(Rate) as Rate  
            from #a
            group by EffectiveDate,rtrim(CurrencyType)
            ) as x
       pivot (MAX(Rate)for CurrencyType in ('+@groupField+')) as pvt
       order by EffectiveDate desc'
      EXEC (@sql)
     
      drop table #a

        end
     
     --execute [R_Parities_Config_CurrencyExchangeRate_V2] 'CAD,USD','USD','2010-12-12','2016-12-12'
     
     --select distinct ToCode,FromCode from Config_CurrencyExchangeRate
    GO

  • 相关阅读:
    PHP文件上传错误类型及说明
    PHP截取字符串 兼容utf-8 gb2312
    php根据日期获得星期
    js根据日期获得星期
    股票的趋势以及高效买入
    制定自己的选股原则
    股市生存法则
    JSP学习
    ANdroid URL
    Adroid 展开收起效果实现
  • 原文地址:https://www.cnblogs.com/dwuge/p/5261204.html
Copyright © 2020-2023  润新知