473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ORDER BY CASE Problem

10 New Member
Hi Im trying to do the following but keeps giving me an "The data types of the result-expression are not compatible". What am i doing wrong?

SELECT PART_NAME, ROWNUM
FROM
(SELECT PART_NAME, ROW_NUMBER() OVER(ORDER BY CASE columnName WHEN('PART_ID') THEN PART_ID ELSE PART_NAME END) AS ROWNUM
FROM NULLID.PARTS) PARTS
WHERE ROWNUM BETWEEN 21 AND 30;
Aug 25 '07 #1
2 3412
frankmusion
10 New Member
Ok I got the solution. I hope this helps someone! Each CASE must output the same DATA TYPE. So if you have a CASE with int columns and varchars columns then all you have to do is have 2 CASE Statements and seperate them by comma's.

exp:

ORDER BY CASE WHEN (Predicate) THEN VarcharColumnn END, CASE WHEN (Predicate) THEN IntColumn END

Can anyone confirm if this is the best way to do this if you have to Order by different type columns?
Aug 26 '07 #2
shalini kudapa
3 New Member
Hi Im trying to do the following but keeps giving me an "The data types of the result-expression are not compatible". What am i doing wrong?

SELECT PART_NAME, ROWNUM
FROM
(SELECT PART_NAME, ROW_NUMBER() OVER(ORDER BY CASE columnName WHEN('PART_ID') THEN PART_ID ELSE PART_NAME END) AS ROWNUM
FROM NULLID.PARTS) PARTS
WHERE ROWNUM BETWEEN 21 AND 30;


Problem i think is with the data types of the attributes. the values the inner query is returning is not same as the data types of the attributes(column names) specified in the outer query
Aug 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
1729
by: Bart Van der Donck | last post by:
Hello, I have a table, say ---------- ID|myvalue ---------- 1|B 2|C 3|A
13
12123
by: Dark Rayden | last post by:
Hi! I recently got a strange problem and I have no idea on the solution. I try to do a ORDER BY statement with a fixed order of values, because my client want's it this way. My approach is...
11
3789
by: jguilford | last post by:
I have created a SQL Stored Procedure that uses a Case statement to determine the Order By. For one of the Case statements I am trying to turn a Char field into Datetime in for the Order By,...
7
2735
by: JJ_377 | last post by:
Can someone tell me why SQL seems to ignore my order by clause? I tried to run through the debugger, but the debugger stops at the select statement line and then returns the result set; so, I have...
1
1688
by: Tony Johansson | last post by:
This class template and main works perfectly fine. But could be better. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter...
3
1448
by: Paul T. Rong | last post by:
Hello there, I am making a report using codes bellow (a part of): ------------------------------- Select Case Forms!!TopBoard Dim strGetSQL As String
7
6319
by: Giles | last post by:
An ASP page outputs data from the query "Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER BY threadID, datesent" (Access mdb) threadID is a string (OK, I know!), which means...
104
10759
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
4
4299
by: Pacific Fox | last post by:
I am using a dynamic order by statement; ORDER BY CASE @sort WHEN 0 THEN CAST( COALESCE( t2.RANK, 0 ) + COALESCE( t3.RANK, 0 ) AS CHAR( 5 ) ) WHEN 1 THEN C.title WHEN 2 THEN CAST( CEILING( ....
0
1876
by: shipmen | last post by:
Hi all ! This is my first post here. I am totally new to db2 and last night I faced with this problem: I want to order my query results by different columns in ORDER BY clause using CASE...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.