-
In EMP table when I execute the syntax
Select * from emp where ename in('king','Allen','Blair','Tony')
it gives the output in the same sequence of names as stored in table e.g first allen,tony,king and then blair. But I require the output in the same sequence same as in query as king,allen,blair and then tony.
In Oracle I can do it by Decode function but in SQL server there is no DECODE function.
Please help
-
Decode function
You could write your own DECODE function as a stored procedure in a sql/server database and then use it as with Oracle.
By the way, would you explain how you do it with a DECODE?
Bye, Rayd
-
select . . .
order by decode(field_to_order_by,'first_in_order',1,'second_in_order',2,3);
-
I got it. I used CASE to solve this problem.
select ename from emp where ename= CASE
WHEN 'james' THEN '1'
WHEN 'king' THEN '2'
WHEN 'allen' THEN '3'
WHEN 'clark' THEN '4'
END in('1','2','3','4') order by CASE ename
WHEN 'james' THEN '1'
WHEN 'king' THEN '2'
WHEN 'allen' THEN '3'
WHEN 'clark' THEN '4'
END
Thanks for all
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
|