sql - Optional filter on a left join column -


Text after "itemprop =" text ">

How do I process problems involving wrapping my head around a process that includes an optional filter on joining in a left Are coming

I have two tables, problems and customer_pace. Not all issues have been linked to a customer location. So I'm fine with this as a starting point:

  Select I.Issue_Number, C.Customer_Location_Code Issues I join Customer_Location C.Customer_Location_Key = I.Customer_Location_Key ISSUE_NUMBER Left | Customer_space 0 Chicago 2 | Zero 3 Chicago 4 | New York   

And it works, it gives me all the issues but if I left the customer location code that would return all 4 issues left null, but for Chicago, only this issue If 1 and 3 will return 1 would want to add an optional parameter to say that set to.

I tried this

  announcement @customer_location_key INT set @customer_location_key = 1.Issue_Number, C.Customer_Location_Code Issues I join LEFT Customer_Location at C C.Customer_Location_Key = I.Customer_Location_Key and C.Customer_Location_Key = @ customer_location_key   

but I get the following results

  ISSUE_NUMBER. Customer_space 0 Chicago 2 | Zero 3 Chicago 4 | Zero   

For some reason I just seem to be having a brain fart and just do not seem to be able to get my head around For

should add the same section below.

  Select DECLARE @customer_location_key INT SET @customer_location_key = 1. I.ssue_Number, I to C. From the customer_ location_code issue, I will get the CP Customer at Customer Location C. Customer Location = of. Customer = location _ (where is zero for customer or C. Customer_ location_key = @ customer_space_key)    

Comments