Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Case Statement

Author  Topic 

amy
Starting Member

30 Posts

Posted - 2002-05-09 : 09:55:59
Hi,

Below is if statement and it is working
==================================
declare @strSQL as nvarchar(300)
If @OfficeType = 'OHA'
set @strSQL = "select * from Office_T where OfficeType IN ( 'OHACO',
'OHARO', 'OHAFO') and PhysicalAddressState IN ( 'TX','AR','LA','NM','OK')
order by OfficeCode"
==========================
ANd now instead of if statement I want to do the case statement

========================================
Select case Officetype
When 'OHA' Then
OfficeType = 'OHACO' Or 'OHARO' or 'OHAFO'
PhysicialAddressState = 'TX' or 'AR' or 'LA' or 'NM' or 'OK'
End
from office_t
order by officecode

===============================================
and here is the error I received from case statement
Line 3: Incorrect syntax near '='

please tell me what did I do wrong in case statement

Thanks alot




Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-09 : 10:10:56
you don't need a case statement, you need a where clause . . .


select
<column_list>
from
office_t
where
(@officetype = 'oha' and
officetype in ('ohaco','oharo','ohafo') and
PhysicalAddressState in ('tx','ar','la','nm','ok')) or
(@officetype = 'Page47' and
officetype in ('Page47a','Page47b') and
PhysicalAddressState in ('md','de','va'))
order by
officecode

 


<O>
Go to Top of Page

amy
Starting Member

30 Posts

Posted - 2002-05-09 : 10:31:55

what did you mean by 'Page47a','Page47b'?

Thanks
quote:

you don't need a case statement, you need a where clause . . .


select
<column_list>
from
office_t
where
(@officetype = 'oha' and
officetype in ('ohaco','oharo','ohafo') and
PhysicalAddressState in ('tx','ar','la','nm','ok')) or
(@officetype = 'Page47' and
officetype in ('Page47a','Page47b') and
PhysicalAddressState in ('md','de','va'))
order by
officecode

 


<O>



Go to Top of Page

Antonio Broughton
Starting Member

6 Posts

Posted - 2002-05-09 : 16:25:27
I think thats just an example if you wanted to add more?


Go to Top of Page
   

- Advertisement -