title: SQL CASE Usage & Pivot
body: <p>In Table A, I have </p>
  
  <pre><code>Cust_ID  Campaign_Date  Campaign_Date1      Campaign_Date2
  1          20160101      20160108             20160115
  2          20160201      20160208             20160215
  </code></pre>
  
  <p>In Table B, </p>
  
  <pre><code>Cust_ID  Bet_Date_Placed_Key  Amount1   Amount2  Amount3
  1          20160101     3         4        6
  1          20160108     4         5        7
  1          20160115     3         4        6
  2          20160201     3         4        6
  2          20160208     4         5        7
  2          20160215     3         4        6
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>Cust_ID Campaign_Date  Amount1   Amount2  Amount3   Campaign_Date1 Amount1   Amount2  Amount3  Campaign_Date2 Amount1  Amount2  Amount3
  
  1         20160101       3          4       6           20160108     4        5          7        20160115       3       4         6
  2         20160201       3          4       6           20160208     4        5          7        20160215       3       4         6
  </code></pre>
  
  <p>If i use the case statement as mentioned below, think there is a pivot also require on the data with respect to the output</p>
  
  <pre><code>select cust_id, 
  campaign_date,
  (case when campaign_date=Bet_Date_Placed_Key then amount1 else null end) as Amount1,
  (case when campaign_date=Bet_Date_Placed_Key then amount2 else null end) as Amount2,
  (case when campaign_date=Bet_Date_Placed_Key then amount3 else null end) as Amount3,
  </code></pre>