zoukankan      html  css  js  c++  java
  • SQL Server表竖列转横向显示

    ----------联合查询结果集存入临时表

    select * into ##tmpa from (select wh_WhName,sum(ps_DiscountMoney) as moneys,psr.wh_Id,Convert(varchar(10),ps_PSRTime,120) as ps_PSRTime
    from PosSaleRecord as psr inner join wareHouse as wh on wh.wh_Id=psr.wh_Id group by psr.wh_Id,wh_WhName,Convert(varchar(10),ps_PSRTime,120)) a

     ----------把临时表竖列转换横向显示

    declare @sql varchar(8000)         --将竖列横向显示
    set @sql = 'select ps_PSRTime '
    select @sql = @sql + ' , (case wh_whname when ''' + wh_whname + ''' then moneys else 0 end) [' + wh_whname + ']'
    from (
    select distinct wh_whname from ##tmpa
    ) as a
    set @sql = @sql + ' into ##tmpPPPt from ##tmpa'
    exec(@sql)

    ----------查询临时表

    select * from ##tmpa   
    select * from ##tmpPPPt

    ----------删除临时表
    drop table ##tmpPPPt
    drop table ##tmpa

  • 相关阅读:
    Python-单例模式
    Django 内置模板标签和过滤器
    Python Built-in Function 学习笔记
    Django 中间件
    Django Form
    Ajax
    Django中cookie和session
    Django中的QuerySet
    Django模型和ORM
    wordpress添加子主题
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2068346.html
Copyright © 2011-2022 走看看