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 |
Nexzus
Starting Member
14 Posts |
Posted - 2013-12-31 : 17:23:00
|
Hello,Say I've got a table with records like this:'lorum ipsum - Phrase One''dolor sit - Phrase One''Consectetur adipisicing - Phrase Two''Magna aliqua - Phrase One''iru dolor - Phrase Two'How can I get a single listing of all 'Phrase One' records in alphabetical order, followed by all 'Phrase Two' records in alpha order.Assume that there is only 'Phrase One' and 'Phrase Two'Thank you.* Edit: I guess a temptable and a bunch of separate queries would do it. Anything in a single query, though? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-12-31 : 23:26:12
|
Why is the data stored like this? Normalize your data into two columns instead.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-01 : 12:07:43
|
[code]SELECT ColumnFROM tableORDER BY STUFF(Column,1,CHARINDEX('-',Column)+1,''),Column[/code]Assuming format is consistent------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-01-01 : 12:39:26
|
SELECT * FROM dbo.Table1 ORDER BY RIGHT(Col, 3), Col1; Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|