View Full Version : select based on where clause (???)


keisx
03-15-2010, 08:12 AM
Hi! I need to create a query, however there are some difficulties and to be honest I don't know if it's even possible. So I have this simple query now:

SELECT Drivers.Driver_name, Drivers.Drivers_surname, Teams.Team_name + '-' + Teams.Team_engine AS Komanda
FROM Teams INNER JOIN Drivers ON Teams.Teams_id = Drivers.Teams_id

What I want to do is, in case there's a match between Teams.Team_name and Teams.Team_engine (which is possible), then select only one of them, otherwise select both, separating them by a dash, as given in my example. Is it possible?

pbaldy
03-15-2010, 08:37 AM
Something along the lines of this pseudo code:

IIf(Name = Engine, Name, Name & "-" & Engine)

keisx
03-15-2010, 08:41 AM
Already solved it with the help of Switch function, however this Iif seems to be shorter, thanks!

pbaldy
03-15-2010, 08:49 AM
No problem, and welcome to the site! In the future, if you solve your own problem, go ahead and post the solution. It may help someone trying to solve their own problem later.