Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Supress Redundant Data?

Author  Topic 

planetoneautomation
Posting Yak Master

105 Posts

Posted - 2010-01-27 : 10:21:46
If a query were to return the following:


BLUE 15 31
BLUE 22 19
BLUE 43 57
RED 19 25
RED 22 98
RED 34 87

Is it possible to have the query display it like this:

Note: please consider the x's below to be spaces - couldn't get this post to appear correctly using actual spaces.


BLUE 15 31
xxxx 22 19
xxxx 43 57
RED 19 25
xxxx 22 98
xxxx 34 87

That is, to replace the redundant BLUE's and RED's with spaces?

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-27 : 10:33:39
That is not what SQL is made for.
If possible then do it in your front end or in your report.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-27 : 10:50:38
quote:
Originally posted by planetoneautomation

If a query were to return the following:


BLUE 15 31
BLUE 22 19
BLUE 43 57
RED 19 25
RED 22 98
RED 34 87

Is it possible to have the query display it like this:

Note: please consider the x's below to be spaces - couldn't get this post to appear correctly using actual spaces.


BLUE 15 31
xxxx 22 19
xxxx 43 57
RED 19 25
xxxx 22 98
xxxx 34 87

That is, to replace the redundant BLUE's and RED's with spaces?

Thanks


this property is available on most reporting tools. its called hide duplicates in sql reports. go to cell properties to find it
Go to Top of Page

planetoneautomation
Posting Yak Master

105 Posts

Posted - 2010-01-27 : 10:52:55
Thanks .. the HP QC Excel Reports tool offers no formatting capabilities at all - otherwise I'd be taking advantage of it. Report users can accomplish this in Excel but I try to deliver with as few data formatting and manipulation requirements as possible.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-27 : 10:54:46
ok in that case do you've unique valued column in your table to define order?
Go to Top of Page

planetoneautomation
Posting Yak Master

105 Posts

Posted - 2010-01-27 : 11:07:32
Yes. Copy of SQL attached. I want to suppress redundant data for 'Application' and 'Severity' which are the Order By fields.

SELECT
BUG.BG_PROJECT as 'Application',
BUG.BG_SEVERITY as 'Severity',
BUG.BG_BUG_ID as 'Defect ID',
BUG.BG_DETECTION_DATE as 'Detected on Date',
BUG.BG_STATUS as 'Status',
BUG.BG_USER_03 as 'Testing Type',
BUG.BG_DETECTED_BY as 'Detected By',
BUG.BG_RESPONSIBLE as 'Assigned To',
BUG.BG_SUMMARY as 'Summary'
FROM BUG
WHERE
BUG.BG_DETECTION_VERSION = '@Environment@' AND
BUG.BG_DETECTION_DATE BETWEEN '@BeginDate@' AND '@EndDate@' AND
BUG.BG_STATUS <> 'Closed' AND
BUG.BG_STATUS <> 'Script Error' AND
BUG.BG_SEVERITY <> '5-Enhancement'
ORDER BY 'Application', 'Severity'
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-01-27 : 11:16:09
If yo have SQL 2005 for later you could use the ROW_NUMBER() function. For example (note this is untested):
SELECT
CASE
WHEN RowNum = 1
THEN [Application]
ELSE 'xxx'
END as [Application],
Severity,
[Defect ID],
[Detected on Date],
[Status],
[Testing Type],
[Detected By],
[Assigned To],
Summary
FROM
(
SELECT
BUG.BG_PROJECT as 'Application',
BUG.BG_SEVERITY as 'Severity',
BUG.BG_BUG_ID as 'Defect ID',
BUG.BG_DETECTION_DATE as 'Detected on Date',
BUG.BG_STATUS as 'Status',
BUG.BG_USER_03 as 'Testing Type',
BUG.BG_DETECTED_BY as 'Detected By',
BUG.BG_RESPONSIBLE as 'Assigned To',
BUG.BG_SUMMARY as 'Summary',
ROW_NUMBER() OVER (PARTITION BY BUG.BG_PROJECT ORDER BY BUG.BG_SEVERITY) AS RowNum
FROM BUG
WHERE
BUG.BG_DETECTION_VERSION = '@Environment@' AND
BUG.BG_DETECTION_DATE BETWEEN '@BeginDate@' AND '@EndDate@' AND
BUG.BG_STATUS <> 'Closed' AND
BUG.BG_STATUS <> 'Script Error' AND
BUG.BG_SEVERITY <> '5-Enhancement'
ORDER BY 'Application', 'Severity'
) AS T
EDIT: Foprgot the PARTITION and addeed Visakh's fix (thanks :) )
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-27 : 11:18:07
quote:
Originally posted by Lamprey

If yo have SQL 2005 for later you could use the ROW_NUMBER() function. For example (note this is untested):
SELECT
CASE
WHEN RowNum = 1
THEN [Application]
ELSE 'xxx',
END as [Application],
Severity,
[Defect ID],
[Detected on Date],
[Status],
[Testing Type],
[Detected By],
[Assigned To],
Summary
FROM
(
SELECT
BUG.BG_PROJECT as 'Application',
BUG.BG_SEVERITY as 'Severity',
BUG.BG_BUG_ID as 'Defect ID',
BUG.BG_DETECTION_DATE as 'Detected on Date',
BUG.BG_STATUS as 'Status',
BUG.BG_USER_03 as 'Testing Type',
BUG.BG_DETECTED_BY as 'Detected By',
BUG.BG_RESPONSIBLE as 'Assigned To',
BUG.BG_SUMMARY as 'Summary',
ROW_NUMBER() OVER (ORDER BY BUG.BG_PROJECT, BUG.BG_SEVERITY) AS RowNum
FROM BUG
WHERE
BUG.BG_DETECTION_VERSION = '@Environment@' AND
BUG.BG_DETECTION_DATE BETWEEN '@BeginDate@' AND '@EndDate@' AND
BUG.BG_STATUS <> 'Closed' AND
BUG.BG_STATUS <> 'Script Error' AND
BUG.BG_SEVERITY <> '5-Enhancement'
ORDER BY 'Application', 'Severity'
) AS T


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-01-27 : 11:20:18
What? What's so hard?


SELECT Col1, Col2, Col3
FROM (
SELECT Col1, Col2, Col3, Col1 AS Col1Order
FROM myTable99 o
WHERE EXISTS (
SELECT Col1, MIN(Col2)
FROM myTable99 i
WHERE o.Col1 = i.Col1
GROUP BY Col1
HAVING o.Col2 = MIN(Col2))

UNION ALL

SELECT '' AS Col1, Col2, Col3, Col1 AS Col1Order
FROM myTable99 o
WHERE NOT EXISTS (
SELECT Col1, MIN(Col2)
FROM myTable99 i
WHERE o.Col1 = i.Col1
GROUP BY Col1
HAVING o.Col2 = MIN(Col2))
) AS XXX
ORDER BY Col1Order, Col2, Col3


Produces


Col1 Col2 Col3
---------- ----------- -----------
BLUE 15 31
22 19
43 57
RED 19 25
22 98
34 87

(6 row(s) affected)



P.S. I am using [ code] ... [ /code] Tags to retain formatting..just remove the space



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -