|
-
June 13th, 2007, 10:08 AM
#1
Help on sql query...
Hi Friends,
I have one query using "IN" clause for example,
select empcode from Employee where EmpCode in ('1006','1001','1005')
In this I am getting results in the order of EmpCode 1001,1005,1006 that is order in the database...
but i want the result in the order of the values in IN clause... that is
1006,1001,1005
how to do that...
please help me...
thanks and Regards,
P.Nagarajan
-
June 13th, 2007, 02:53 PM
#2
Re: Help on sql query...
I don't know a direct way using (in)
but this technique does the work:
Code:
declare @t table (id int identity,val int)
insert into @t values(9)
insert into @t values(12)
insert into @t values(11)
SELECT Employee.*
FROM STUDENT,@t
Where EmpCode = val
order by id
-
June 14th, 2007, 07:04 AM
#3
Re: Help on sql query...
Hi all.
In my opinion isn't possible to do what you want using standard SQL.
You want to set "dinamically" an order when you extract records with the query, specifying the keys' values into the IN clause, but the only way to set the order is adding the ORDER BY clause on a field (or more fields), and you'll get the numerical or alphabetical order.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|