Select and Sorting on the bases of IN clause values

Posted by Puneet20884 under Sql Server on 2/17/2010 | Views : 1727 | Status : [Member] | Replies : 5
Hi,
I need the select Query that gives the result in the order same as the inputs given in 'IN' option.
as

select * from names_table where name in ('pun','lak','nis',trtr)

i need the result in the order as first result of first value then second as second value of IN clause and so on,
i want this to be done in one statement not UNION or UNION ALL and imposingly that the initial physical order is not the same as the inputs provided.

Thanks,
Puneet

Best Regards,
Puneet Sharma - Infosys
Pune, India



Responses

Posted by: Puneet20884 on: 2/17/2010 [Member] Bronze

Up
0
Down
Also please not to use any function in it !!

Best Regards,
Puneet Sharma - Infosys
Pune, India

Puneet20884, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/17/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
am not sure if i understand correctly. Can you provide Data examples in Table and the Results you want to output and don't forget to provide your input.



Thank you for posting at Dotnetfunda
[Administrator]

Puneet20884, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: modi_sanjay-10274 on: 5/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

I was also stuck in the same problem and come out with following option

insteading passing value through In clause make inner join between firat table and the second table (whose provide input value in IN Clause) on common key between both table


Sanjay Modi

Sanjay Modi

Puneet20884, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 5/17/2011 [Member] Starter | Points: 25

Up
0
Down
select * from tab_name where name in (select name from tab_name where name='dddd' union
select name from tab_name where name='aaaa' union select name from tab_name where name='zzz')

Thanks&Regards
LakshmiNarayana Nalluri.

Puneet20884, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: modi_sanjay-10274 on: 5/17/2011 [Member] Starter | Points: 25

Up
0
Down
HI LakshmiNarayana Nalluri

I did not get your reply, is this the solution of above problem or is this question to find out out any solution.




Sanjay Modi

Puneet20884, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response