2019-03-28 SQL Server Table

时间:2019-03-28 11:10:45   收藏:0   阅读:146
-- table 是实际表 view是虚表。你可以认为view是一个查询的结果

-- 声明@tbBonds table

declare @tbBonds table(TrustBondId int not null,shortName nvarchar(500),ClassName nvarchar(20),CouponBasis decimal(8,2))

-- 这里涉及到pivot行转列的知识,可参考上一篇文章
select * from (
    select TrustBondId,ItemCode,ItemValue
    from DealStructure.TrustManagement.TrustBond
    where TrustId=@TrustID    
)p 
pivot
(max(ItemValue) for ItemCode in (ShortName,ClassName,CouponBasis)) t


-- table 表可以和其它表关联
join @tbBonds b on bps.TrustBondId=b.TrustBondId where

  

原文:https://www.cnblogs.com/theDataDigger/p/10613477.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!