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 2005 Forums
 Transact-SQL (2005)
 Multiple if selection

Author  Topic 

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-12-10 : 04:21:33
Hi

I know it is possible, but I can't find the right solution for something simple.

I have in one collumn following data:
Columntest:

Man
Woman
Alien
...

But i need another collumn that shows me like another name for it

so
case
when columntest = 'man' then othername
when columntest = 'woman' then another
...

Ty :)
when

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-10 : 04:28:49
Hi

Using CASE...is fine

-------------------------
R...
Go to Top of Page

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-12-10 : 04:52:10
I tried, but getting errors :/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-10 : 04:55:59
Hi

Can you post the query...
It will helpful for us..


-------------------------
R...
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-10 : 05:02:50
Hi

Syntax is like this..

CASE expression
WHEN expression1 THEN expression1
[[WHEN expression2 THEN expression2] [...]]
[ELSE expressionN]
END


-------------------------
R...
Go to Top of Page

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-12-10 : 05:03:17
SELECT *,
case when Eng_To_Gps_Modellen.Plant = 'france' then 'fra'
when Eng_To_Gps_Modellen.Plant = 'germany' then 'DE'
end as MFR,
FROM Eng_To_Gps_Modellen LEFT JOIN Model_Matrix_EUNANZLAR ON Model_Matrix_EUNANZLAR.MODEL=Eng_To_Gps_Modellen.GPS_Models;
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-10 : 05:05:58
Hi

Try this..

SELECT
*,
CASE
WHEN ENG_TO_GPS_MODELLEN.PLANT = 'FRANCE' THEN 'FRA'
WHEN ENG_TO_GPS_MODELLEN.PLANT = 'GERMANY' THEN 'DE'
END AS MFR
FROM ENG_TO_GPS_MODELLEN
LEFT JOIN MODEL_MATRIX_EUNANZLAR
ON MODEL_MATRIX_EUNANZLAR.MODEL = ENG_TO_GPS_MODELLEN.GPS_MODELS;


-------------------------
R...
Go to Top of Page

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-12-10 : 05:25:23
This is why i hate acces! I'm used to work with SQL 2005.
He still gives a syntax error(missing operator) in query expression CASE.

Is TSQL different from ACCES query?
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-10 : 05:37:26
quote:
Originally posted by IBoonZ

This is why i hate acces! I'm used to work with SQL 2005.
He still gives a syntax error(missing operator) in query expression CASE.

Is TSQL different from ACCES query?



HI

If you using MS - Access You can use IFF() instead of Case..

But you posted in Transact-SQL (2005) thread..

-------------------------
R...
Go to Top of Page

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-12-10 : 05:46:53
he, did it in design view, so if other ppl like me have this problem.
I did this
Country: IIf(Eng_To_Gps_Modellen.Plant="German";"de";IIf(Eng_To_Gps_Modellen.Plant="France";"FR";IIf(Eng_To_Gps_Modellen.Plant="Austr";"AS";IIf(Eng_To_Gps_Modellen.Plant="Island";"IL";IIf(Eng_To_Gps_Modellen.Plant="USA";"U";"No country")))))

And Ty for the help :D
Go to Top of Page
   

- Advertisement -