how to divide data in multiple columns in tsql
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
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...
Sales Table Structure
CREATE TABLE [dbo].[Sales](
[SalesId] [int] IDENTITY(1,1) NOT NULL,
[MemoNo] [int] NULL,
[CustomerID] [int] NULL,
[SalesmanID] [int] NULL,
开发者_StackOverflow社区[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.........
This should be a simple
SELECT
SalesId, [Name], GrandTotal as 'Price'
FROM
dbo.Sales
WHERE
(some condition)
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...
Use SQL Server and T-SQL to retrieve the data, and use SQL Server Reporting Services to format the output to your needs.
I think something could be done along the lines of...
SELECT
SELECT *
FROM (SELECT SalesId, Name, Price
FROM Sales S2
WHERE S2.SalesId = S1.SalesId ) as Tab1,
SELECT *
FROM (SELECT SalesId, Name, Price
FROM Sales S2
WHERE S2.SalesId = S1.SalesId + 1) as Tab2,
SELECT *
FROM (SELECT SalesId, Name, Price
FROM Sales S2
WHERE S2.SalesId = S1.SalesId + 2) as Tab3
FROM Sales
WHERE ...every third row...;
I can't fill in the full details because I'm no expert on TSQL, and also the table doesn't contain a SlNo, Name or Price which you presumably have to get from somewhere. Whether that's an improvement on going to code as Ronald Wildenberg suggests is a matter of taste.
精彩评论