Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2008, 01:02 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Oh, yeah...sorry...I had started to approach it a slightly different way and then changed my mind. Forgot to go back to the GROUP BY to change it to match.
 
Old September 2nd, 2008, 01:23 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think you can do this with MS-SQL, this can be done with Oracle which supports better use of aggregation and sub queries.

When using MS-Sql I put the data into a temp table and add some fields, one of the fields being the right 3 characters, then in another field I initially store blanks or null. Then I go back and update the temp table setting the last field to "dupe" or whatever you want to return. Then I select the first and the last field to get what you want. But its done via a temp table, not just a straight query. If you need an example of how the code works, request it.

 
Old September 2nd, 2008, 01:37 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Ummm...if you can't do it with SQL Server, then I guess he must have been imagining things when he said "Excellent!"

Yes, you can. Yes, it worked.

As he said, the final WORKING form was

SELECT data.part
FROM data,
     ( SELECT LEFT(part,5) AS prefix, MIN(SUBSTRING(part,6,1) AS subtype, RIGHT(part,3) AS series
       FROM data
       GROUP BY LEFT(part,5), RIGHT(part,3) ) AS check
WHERE LEFT(data.part,5) = check.prefix AND RIGHT(data.part,3) = check.series
ORDER BY check.prefix, check.subtype, check.series, data.part

Only mistake I made was I'd left a + sign in where the red comma now is.
 
Old September 2nd, 2008, 09:07 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Real glad I'm not the only one who needs a trip to the eye doctor... ;)

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Order by In Report mateenmohd Access 3 December 6th, 2006 08:17 AM
ORDER BY a column? gilgalbiblewheel Classic ASP Databases 1 March 30th, 2005 10:37 AM
Order By with Union agarwalmk SQL Language 3 February 18th, 2004 11:33 AM
Order by on a subform bjackman Access 1 January 16th, 2004 01:22 PM
document node order vs sort node order. ladyslipper98201 XSLT 2 June 5th, 2003 11:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.