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.
| 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 31BLUE 22 19BLUE 43 57RED 19 25RED 22 98RED 34 87Is 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 31xxxx 22 19xxxx 43 57RED 19 25xxxx 22 98xxxx 34 87That 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. |
 |
|
|
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 31BLUE 22 19BLUE 43 57RED 19 25RED 22 98RED 34 87Is 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 31xxxx 22 19xxxx 43 57RED 19 25xxxx 22 98xxxx 34 87That 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 |
 |
|
|
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. |
 |
|
|
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? |
 |
|
|
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.SELECTBUG.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 BUGWHEREBUG.BG_DETECTION_VERSION = '@Environment@' ANDBUG.BG_DETECTION_DATE BETWEEN '@BeginDate@' AND '@EndDate@' ANDBUG.BG_STATUS <> 'Closed' ANDBUG.BG_STATUS <> 'Script Error' ANDBUG.BG_SEVERITY <> '5-Enhancement'ORDER BY 'Application', 'Severity' |
 |
|
|
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], SummaryFROM( 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 :) ) |
 |
|
|
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], SummaryFROM( 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
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-01-27 : 11:20:18
|
What? What's so hard?SELECT Col1, Col2, Col3FROM ( 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 XXXORDER BY Col1Order, Col2, Col3 ProducesCol1 Col2 Col3---------- ----------- -----------BLUE 15 31 22 19 43 57RED 19 25 22 98 34 87(6 row(s) affected) P.S. I am using [ code] ... [ /code] Tags to retain formatting..just remove the spaceBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|
|
|
|