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
 Transact-SQL (2000)
 Foxpro to SQL conversion

Author  Topic 

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-03-04 : 16:34:41
I am trying to convert foxpro code to SQL Server, and ther is a bit of code I am having trouble with. Hope someone can help...
Thanks

case colltmp.SS_ACTIV='13'
if colltmp.FUNCTION = '50' .or. colltmp.function='60'
replace colltmp.program with 'DE'
else
if inlist
(colltmp.function,'00','01','02','03','04','05','07','08','09','12','13','30','41')
replace colltmp.program with 'CI'

endif
endif

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-04 : 16:41:36
CASE statements go like this:

CASE WHEN Column1 = 1 THEN 2
WHEN Column2 = 4 THEN 3
END

I don't know what your CASE statement is currently doing, so I can't convert it. But maybe something like this:

case colltmp.FUNCTION IN ('50','60') THEN colltmp.program = 'DE'
WHEN inlist IN
(colltmp.function,'00','01','02','03','04','05','07','08','09','12','13','30','41') THEN colltmp.program = 'CI'
END
WHERE colltmp.SS_ACTIV='13'

Look up CASE in SQL Server Books Online for syntax.

Tara
Go to Top of Page

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-03-04 : 16:45:12
Thanks Tara...I was curious to know how to integrate an If statement into a case in SQL, is that possible?

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-04 : 16:46:27
No it is not. You can run IFs but not within a SELECT statement.

IF @Var1 = 2
PRINT 'Do something'
ELSE
PRINT 'Do something else'


Tara
Go to Top of Page

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-03-04 : 16:49:33
Tara: Is it posible to use IIF in a case or should I consider embedding case in one other?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-04 : 16:50:59
IIF doesn't exist in SQL Server.

I'm not sure if you can embed multiple CASE statements in a query.

Tara
Go to Top of Page

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-03-04 : 16:52:46
Thanks for all your help Tara.
Go to Top of Page
   

- Advertisement -