datetime century date into pad dynamic cursor money percent sp job isnumeric isdate over update
SQLUSA.com
SQL 2008 GRAND SLAM ON 49 CD
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL Server Training SQL 2005 Scripts SQL 2008 Articles
SQL JOBS News Format Developer
How to hide repeating cell values in query results?

Execute the following Microsoft T-SQL example script in SQL Server Management Studio Query Editor to demonstrate how to blank out repeating values in query results.

------------
-- Microsoft SQL Server T-SQL hiding repeating values in parent-child join queries
------------
-- SQL repeating values of SalesOrderID are blanked out
-- MSSQL row number over partition by - case function
USE AdventureWorks;
SELECT   SalesOrderID = CASE
                          WHEN RowNumber = 1 THEN convert(VARCHAR,a.SalesOrderID)
                          ELSE ''
                        END,
         a.SalesOrderDetailID,
         OrderQuantity = a.OrderQty,
         RowNumber
FROM     (SELECT RowNumber = row_number()
           OVER(PARTITION BY sod.SalesOrderID ORDER BY sod.SalesOrderDetailID),
                 soh.SalesOrderID,
                 SalesOrderDetailID,
                 OrderQty
          FROM   Sales.SalesOrderHeader soh
                 INNER JOIN Sales.SalesOrderDetail sod
                   ON soh.SalesOrderID = sod.SalesOrderID
          WHERE  Year(soh.OrderDate) = 2004
                 AND Month(soh.OrderDate) = 2) a
ORDER BY a.SalesOrderID,
         a.SalesOrderDetailID
GO;
/* Partial Results
 
SalesOrderID      SalesOrderDetailID      OrderQuantity     RowNumber
63119             81712                   1                 1
63120             81713                   2                 1
                  81714                   1                 2
                  81715                   2                 3
63121             81716                   2                 1
                  81717                   2                 2
63122             81718                   1                 1
                  81719                   4                 2
                  81720                   4                 3
63123             81721                   1                 1
*/
 
-- SQL select parent-child inner join query with repeating SalesOrderID value
SELECT
                 soh.SalesOrderID,
                 SalesOrderDetailID,
                 OrderQty
          FROM   Sales.SalesOrderHeader soh
                 INNER JOIN Sales.SalesOrderDetail sod
                   ON soh.SalesOrderID = sod.SalesOrderID
          WHERE  Year(soh.OrderDate) = 2004
                 AND Month(soh.OrderDate) = 2
          ORDER BY      soh.SalesOrderID,
                              sod.SalesOrderDetailID;
GO
/* Partial results
 
SalesOrderID      SalesOrderDetailID      OrderQty
63119             81712                   1
63120             81713                   2
63120             81714                   1
63120             81715                   2
63121             81716                   2
63121             81717                   2
63122             81718                   1
63122             81719                   4
*/

 

------------

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
Microsoft SQL Server 2012 Training Videos at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Accounting
Administrative
Advertising
Arts
Architecture
Banking
Business Intelligence
Career Jobs
Celebrity
Computer
Consulting
Customer Service
Education
Engineering
Entertainment
Entry Level
Executive
Federal
Finance
Government
Hardware
Healthcare
Hospital
Human Resources
Information Technology
Insurance
Internet
Job Openings
Laboratory
Law Enforcement
Legal
Logistics
Manufacturing
Marketing
Medical
Military
Nursing
Pharmaceutical
Physician
Public Relations
Publishing
Real Estate
Restaurant
Retail
Sales
Social Media
Software
SQL Database
Telecomm
Therapist
Training
Transportation
Truck Driver
Travel
Web
Work from Home

FREE SS SQL / BI OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011 Microsoft Community Contributor 2012

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts

JOIN US ON TWITTER

Copyright 2005-2012, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.