I have a table where the data could be like these below:
CusID | Name | State | PhyAddress
160285 | FYZPZ | NULL | 0
160285 | FYZPZ | NJ | 1
160285 | FYZPZ | NJ | 1
or
CusID | Name | State | PhyAddress
160285 | FYZPZ | NJ xx | 1
or
CusID | Name | State | PhyAddress
160285 | FYZPZ | NULL | 0
160285 | FYZPZ | NJ xx | 0
I need to get the default state for the user. And the logic is:
The result should display the physcial state first (PhyAddress = 1) and if
there is no physical address (PhyAddress = 0), then it should display the mailing adress state (PhyAddress = 0). If there are none, the state can be blank.
There are multiple customers in the table and they each can have multiple rows like above and I need to get the default state for each customer.
The resuts needs to show a result of CusID, Name, State
Please help me with the query. TIA