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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Order By question

Author  Topic 

pucci70
Starting Member

20 Posts

Posted - 2002-09-19 : 04:41:41
I have this SELECT: (with col ID_GRUPPO PK CLUS IDX)

SELECT ID_GRUPPO, NOME FROM dbo.T_ER_GRUPPI_MENU vocegruppo
WHERE ID_GRUPPO IN (23,5,6)

and return this values:

ID_GRUPPO - NOME
----------------
5 Abbbb
5 Abbbb
6 Bcccc
23 Dvvvv
23 Dvvvv

but i want this literal order (23,5,6) not ASC or DESC:

ID_GRUPPO - NOME
----------------
23 Dvvvv
23 Dvvvv
5 Abbbb
5 Abbbb
6 Bcccc

suggestion...?

================================
Thank You All For Your Help ^^
Luca

rihardh
Constraint Violating Yak Guru

307 Posts

Posted - 2002-09-19 : 04:55:13
What rule are you using for your ordering (why 23,5,6...)?

I can't see any rule of ordering for your ID_GRUPPO, nor your NOME column.

Go to Top of Page

pucci70
Starting Member

20 Posts

Posted - 2002-09-19 : 05:00:11
The default rule is ID_GRUPPO in ASC i suppose, beacause this col is PK CLUS IDX, but i want the rule described in IN clause:
first 23, second 5, ecc...

================================
Thank You All For Your Help ^^
Luca
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-19 : 05:02:50
SELECT ID_GRUPPO, NOME FROM dbo.T_ER_GRUPPI_MENU vocegruppo
WHERE ID_GRUPPO IN (23,5,6)
order by case ID_GRUPPO when 23 then 1 when 5 then 2 else 3 end



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pucci70
Starting Member

20 Posts

Posted - 2002-09-19 : 05:28:53
Thanks 1000!


================================
Thank You All For Your Help ^^
Luca
Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2002-09-19 : 06:41:45
Nice hard coding nr :)

How about

SELECT ID_GRUPPO, NOME FROM dbo.T_ER_GRUPPI_MENU vocegruppo
WHERE ID_GRUPPO IN (23,5,6)
ORDER BY CONVERT(VARCHAR, ID_GRUPPO)

That will make the order literal.

Go to Top of Page
   

- Advertisement -