May 18, 2015 at 9:41 am
Is it possible to join based on conditions
I am trying to join Project_Code with Manager.Code but if the project_code is blank then it should look for Project_CostCenter and Join with ManagerCode .
Project_Code = Manager.Code ( But if Project_Code is blank)
Then Project_Cost_Center = Manager.code
I tried COALESCE but somehow my results don't show as expected, also the Projectcode is blank and not Null
May 18, 2015 at 9:57 am
sharonsql2013 (5/18/2015)
Is it possible to join based on conditionsI am trying to join Project_Code with Manager.Code but if the project_code is blank then it should look for Project_CostCenter and Join with ManagerCode .
Project_Code = Manager.Code ( But if Project_Code is blank)
Then Project_Cost_Center = Manager.code
I tried COALESCE but somehow my results don't show as expected, also the Projectcode is blank and not Null
You could try something like:
Manager.Code = (CASE WHEN Project_Code != '' THEN Project_Code ELSE Project_Cost_Center END)
Chances are performance won't be great, but it should provide the condition you're looking for.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
May 18, 2015 at 10:21 am
Yes, I will definitely try this.
May 19, 2015 at 5:05 am
Or something like
ON
(Project_Code = Manager.Code AND Project_Code <> '')
OR
(Project_Code = '' AND Project_cost_center = Manager.Code)
-- Itzik Ben-Gan 2001
May 19, 2015 at 6:01 pm
sharonsql2013 (5/18/2015)
Is it possible to join based on conditionsI am trying to join Project_Code with Manager.Code but if the project_code is blank then it should look for Project_CostCenter and Join with ManagerCode .
Project_Code = Manager.Code ( But if Project_Code is blank)
Then Project_Cost_Center = Manager.code
I tried COALESCE but somehow my results don't show as expected, also the Projectcode is blank and not Null
Please post your code so we can try to figure something else out because conditional joins typical result in some pretty slow performance and pretty high resource usage.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply