Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

using case statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pintu - 12 Mar 2008 04:35 GMT
Hi Friends,
I want to use "in" clause in case statement as shown below.
e.g
select * from employee
where empid in
              case i_desgn
               when 'HR' then (1,2,3,4,5)
               when 'MD' then 1
               else   7
               end

Though i did this using if-elsif but there is repetation of query. So
i want this way to implement..Please help as soon as possible..

Thanks
Priyabrata
Michael Nemtsev [MVP] - 12 Mar 2008 04:49 GMT
Hello pintu,

u can't use CASE out of SELECT statement. u need to rewrite your query

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

p> Hi Friends,
p> I want to use "in" clause in case statement as shown below.
p> e.g
p> select * from employee
p> where empid in
p> case i_desgn
p> when 'HR' then (1,2,3,4,5)
p> when 'MD' then 1
p> else   7
p> end
p> Though i did this using if-elsif but there is repetation of query. So
p> i want this way to implement..Please help as soon as possible..
p>
p> Thanks
p> Priyabrata
bruce barker - 12 Mar 2008 06:23 GMT
you were close. in sql case is an expression and needs to be used as a
compare in a where clause:

 select * from employee
 where case
         when i_desgn = 'HR' and empid in (1,2,3,4,5) then 1
         when i_desgn = 'MD' and empid in (1) then 1
         when empid in (7) then 1
         else 0
       end = 1

-- bruce (sqlwork.com)

> Hi Friends,
>  I want to use "in" clause in case statement as shown below.
[quoted text clipped - 12 lines]
> Thanks
> Priyabrata

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.