Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Naming Order on results.t-sql

Posted on 2009-04-06
2
Medium Priority
?
196 Views
Last Modified: 2012-05-06
Hi,
I have written some code. and i have added a colum which catagories the results.
So each row will have a catagory of say, 'Current', 'WholeSale', 'Example' ok.
So i want to be able to order the results by the Catagory.
So i would like the results as follows with
Example as the first catagory,
Wholesale as the second catagory and Current as the last catagory.

i've been trying to get the order correct and it doesn't seem to work the only way i get it to work is doing the following:
putting 1.1 beside the first catagory i want returned and then 1.2 beside the second and so on and so on.
Please bear in mind, this is only an example of the code i am using, my actual code has up to 20 different catagories.

I don't want the end user to see 1.1 and 1.2 beside the catagory name,
I tried using Substring in the case statement but that just hinders the order of the catagory as if i didn't use the numbering system.

I am using SSRS Visual Studio to display my results, i thought i could use substring in the expression to cut the numbering out (substring(catagory,5,10) but that throws an error. Substring does not seem to be recognised.

Can anyone help or advise me on this please?
Regards,
Putoch


create table test_table(
somedata varchar(10),
Catagories varchar(20))
 
Insert into test_table values ('qwjklerh','Example')
Insert into test_table values ('dddddsdfds','Wholesale')
Insert into test_table values ('dddddsd','Example')
Insert into test_table values ('ffsfds','Current')
Insert into test_table values ('gwerewr','Current')
 
 
select 
somedata,
case when catagories like 'Example' then '1.0 Example'
When catagories like 'Wholesale' then '1.2 WholeSale' 
when catagories like 'Current' then '1.3 Current' End catagories
 from test_table
 
Order by case when catagories like 'Example' then '1.0 Example'
When catagories like 'Wholesale' then '1.2 WholeSale' 
when catagories like 'Current' then '1.3 Current' End

Open in new window

0
Comment
Question by:Putoch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
udaya kumar laligondla earned 600 total points
ID: 24075775
create a table called orderTab with Catagories and orderNo
then use
select
somedata,  cast(o.OrderNo as varchar) +'  ' + t.catagories
 from test_table t
join orderTab o on(test_table.Catagories =  o.Catagories)  
order by o.OrderNo
0
 

Author Comment

by:Putoch
ID: 24075978
Ah yes, that worked, thank you!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question