473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Surprising - SQL Quey - order by !!

24 New Member
Hi all,

The query below is not compiling. Please help:

Expand|Select|Wrap|Line Numbers
  1. Select case
  2.                 when isNull(a.[USER_ID],0)=0 Then char(43)
  3.                 when isNull(t.[USER_ID],0)=0 Then char(45)
  4.                 else char(160)
  5.         end as ind, count(*)
  6. from T1 t
  7. left outer join T2 a on
  8.                 t.ASSIGNMENT_ID = a.ASSIGNMENT_ID
  9. group by ind
  10. order by ind
Nov 7 '07 #1
5 1326
iburyak
1,017 Recognized Expert Top Contributor
You can do following ways:

1.

Expand|Select|Wrap|Line Numbers
  1. Select case
  2.                 when isNull(a.[USER_ID],0)=0 Then char(43)
  3.                 when isNull(t.[USER_ID],0)=0 Then char(45)
  4.                 else char(160)
  5.         end as ind, count(*)
  6. from T1 t
  7. left outer join T2 a on
  8.                 t.ASSIGNMENT_ID = a.ASSIGNMENT_ID
  9. group by case
  10.                 when isNull(a.[USER_ID],0)=0 Then char(43)
  11.                 when isNull(t.[USER_ID],0)=0 Then char(45)
  12.                 else char(160)
  13.         end
  14. order by 1
2.

Expand|Select|Wrap|Line Numbers
  1. Select ind, count(*) 
  2. FROM (
  3.     Select case
  4.                     when isNull(a.[USER_ID],0)=0 Then char(43)
  5.                     when isNull(t.[USER_ID],0)=0 Then char(45)
  6.                     else char(160)
  7.             end as ind
  8.     from T1 t
  9.     left outer join T2 a on
  10.                     t.ASSIGNMENT_ID = a.ASSIGNMENT_ID) a
  11. group by ind
  12. order by ind
Good Luck.
Nov 7 '07 #2
TimHop12
24 New Member
Thanks a lot iburyak!

This helped...
Nov 7 '07 #3
TimHop12
24 New Member
Thanks a lot iburyak. This helped...

But please help me understanding, why the original query is not working? Where I am missing at. Appreciate your help... Thank you.
Nov 8 '07 #4
porter
2 New Member
TimHop12,

Just want to share may idea why your codes didn't work, because you cant group by a "alias" name in the group statement. on the other hand, if you want to use the "alias" name, you should do a select statement in another select statement.
Nov 8 '07 #5
iburyak
1,017 Recognized Expert Top Contributor
TimHop12,

See Porter's respond it is exactly what it is.

If you need more clarification let us know and we will explain in more details.


Good Luck.
Nov 8 '07 #6

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
9
by: Steven T. Hatton | last post by:
The following works: template <typename T> struct ID3M{ static const T ID; }; template <typename T> const T ID3M<T>::ID = {{1,0,0},{0,1,0},{0,0,1}};
12
by: Jack | last post by:
Imagine if someone asked which of the follwing two methods of encoding an integer into a byte array was quicker. The purpose is in preparation for sending across a socket as part of a 'header'....
2
by: naija naija | last post by:
Hello guys i made a Datagrid with Editing,Update and Cancel using VS.NET. to my surprise nothing is on the screen after compilation .. By code below:- Imports System.Data Imports...
3
by: touf | last post by:
Hi, I like to create a query builder to allow the user to create his statistics and see them using Cristal report Any idea about how to do this, is there any controls that can help me. Thanks.
7
by: codergem | last post by:
Hello Friends Can anyone help me where exactly at what address the *p is storing the updated value ( which is 99). const int k=9; int *p=(int *)&k; cout<<"Addr of k : "<<&k<<" "<<p;
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
4
by: David Abrahams | last post by:
I'm seeing highly surprising (and different!) behaviors of PyImport_ImportModule on Linux and Windows when used in a program with python embedding. On Linux, when attempting to import a module...
1
by: rparcha | last post by:
How to convert following MS access quey to SQL server statement ACCESS: Testx: IIf(Mid(dbo_ITMaster!City,1,2)="AB",IIf(Mid(dbo_ITMaster!Plan,1,3)<>"XYZ","M",IIf(dbo_ITMaster!Center="1111", "A",...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.