Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Click here to copy the following block
CREATE TABLE #Test (Description CHAR(5));
INSERT #Test VALUES('AAAAA');
INSERT #Test VALUES('BAAAB');
INSERT #Test VALUES('HAAAB');
INSERT #Test VALUES('MMMMM');
INSERT #Test VALUES('TAAAR');
INSERT #Test VALUES('XXXXZ');
INSERT #Test VALUES('ZZZZA');
SELECT * FROM #Test;
/*
Description
-----------
AAAAA
BAAAB
HAAAB
MMMMM
TAAAR
XXXXZ
ZZZZA
*/

GO
-- Generate sequence using CROSS JOIN. Just an example, may not be the best way always
SELECT t1.DESCRIPTION,
SUM(CASE WHEN t2.DESCRIPTION <= t1.DESCRIPTION THEN 1 ELSE 0 END) AS Sequence
FROM #Test t1 CROSS JOIN #Test t2
GROUP BY t1.DESCRIPTION
ORDER BY t1.DESCRIPTION;
/*
DESCRIPTION Sequence  
----------- -----------
AAAAA         1
BAAAB         2
HAAAB         3
MMMMM         4
TAAAR         5
XXXXZ         6
ZZZZA         7
*/

-- Using a sub-query...
SELECT t1.DESCRIPTION,
(SELECT COUNT(*) FROM #Test t2 WHERE t2.DESCRIPTION <= t1.DESCRIPTION) AS Sequence
FROM #Test t1
ORDER BY t1.DESCRIPTION;
/*
DESCRIPTION Sequence  
----------- -----------
AAAAA         1
BAAAB         2
HAAAB         3
MMMMM         4
TAAAR         5
XXXXZ         6
ZZZZA         7
*/


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.