如何在tsql中将数据分成多列 [英] how to divide data in multiple columns in tsql

查看:36
本文介绍了如何在tsql中将数据分成多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有大约 1000 行,我想按列分组进行划分.我的意思是以下格式

i have around 1000 of rows in database which i want to divide in column group wise. i mean in following format

SlNo.    Name    Price      SlNo.    Name    Price      SlNo.    Name    Price

我如何编写查询以在 rdlc 报告 vs 2008 中以上述格式显示数据我无法以这种格式显示数据.任何帮助将不胜感激...

how i can write query to show data in above format as in rdlc report vs 2008 i am unable to show data in this format. Any help would be appreciated...

销售表结构

CREATE TABLE [dbo].[Sales](
[SalesId] [int] IDENTITY(1,1) NOT NULL,
[MemoNo] [int] NULL,
[CustomerID] [int] NULL,
[SalesmanID] [int] NULL,
[DisRate] [int] NULL,
[CoolingCh] [int] NULL,
[GrandTotal] [int] NULL,
[SubTotal] [int] NULL,
[BillDate] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AddedOn] [datetime] NULL,
 CONSTRAINT [PK_Sales] PRIMARY KEY CLUSTERED 
(
[SalesId] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

谢谢.........

thanks.........

推荐答案

这应该是一个简单的

SELECT 
    SalesId, [Name], GrandTotal as 'Price'
FROM 
    dbo.Sales 
WHERE
    (some condition)

检索您需要的所有数据,然后在 SQL Server 报表设计器中使您的报表显示三列重复三遍...

to retrieve all the data you need, and then in the SQL Server Report Designer make your report display the three columns repeated three times across...

使用 SQL Server 和 T-SQL 检索数据,并使用 SQL Server Reporting Services 根据您的需要格式化输出.

Use SQL Server and T-SQL to retrieve the data, and use SQL Server Reporting Services to format the output to your needs.

这篇关于如何在tsql中将数据分成多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆