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
 General SQL Server Forums
 New to SQL Server Programming
 select based on where clause (???)

Author  Topic 

keisx
Starting Member

2 Posts

Posted - 2010-03-15 : 11:45:38
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?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-15 : 11:49:00
[code]SELECT Drivers.Driver_name, Drivers.Drivers_surname, Teams.Team_name + COALESCE( '-' + NULLIF(Teams.Team_engine,Teams.Team_name),'') AS Komanda
FROM Teams INNER JOIN Drivers ON Teams.Teams_id = Drivers.Teams_id[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

keisx
Starting Member

2 Posts

Posted - 2010-03-15 : 12:01:05
Sorry, didn't mention I was using MS Access 2003, therefore function COALESCE is not found and the query doesn't work. Is it possible to do it in a different way?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-15 : 12:06:15
then post this in access forum

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -