title: how to embed if statement for sql cmd export
body: <p>I have a SQL cmd that runs and exports out a CSV file.   How do I compare to fields that are being returned in my query and display text in the export based on those fields?     Where it has the "Title" section I want to compare 2 fields "First_Unit" and "Unit".  If they are equal I want to add text "Primary" if they are not then I want "Backup".    So it is in this section and here is how it would look logically: 'BWC - ' + UPPER(Complaint) + <strong>'Primary' ELSE 'Backup'</strong> as Title.   So the 2 texts I would want to appear at the end of this data in that column.</p>
  
  <p>Thanks
  TJ    </p>
  
  <p>Here is original query:</p>
  
  <pre><code>sqlcmd -S PDCAD -d Ver2_CAD -E -Q "select Active_Calls.Call_Number AS 'Event ID',Officer_IDs AS 'Officer Badge ID', Date_Received AS 'Officer Dispatched DateTime',Time_Complete AS 'Officer Cleared DateTime',Active_Calls.Call_Number AS 'Report Number',UPPER(Complaint) AS 'Category', '' as Tag,'BWC - ' + UPPER(Complaint) as Title,Actual_Incid_Location AS 'Street',Actual_Incid_City AS 'City', ISNULL(Actual_Incid_State,'CT') AS 'State', RIGHT('0'+CONVERT(VARCHAR,Actual_Incid_ZIP),5) AS 'ZIP Code' from Active_Calls INNER JOIN CALLUNITDATA CALLUNITDATA ON Active_Calls.Call_Number=CALLUNITDATA.Call_Number WHERE Officer_IDs &lt;&gt; 'NHFD' AND Officer_IDs &lt;&gt; 'POST53' AND Officer_IDs &lt;&gt; 'POST54' AND Officer_IDs &lt;&gt; 'POST52'  AND Officer_IDs &lt;&gt; 'DFD' AND Officer_IDs &lt;&gt; 'NFD' AND Officer_IDs &lt;&gt; 'DFD3' AND Officer_IDs &lt;&gt; 'NHFD2' AND Officer_IDs &lt;&gt; 'UNIT50' AND Officer_IDs &lt;&gt; 'NFD2' AND Officer_IDs &lt;&gt; 'DFD2' AND Officer_IDs &lt;&gt; '1129'AND Officer_IDs &lt;&gt; '2120' AND Officer_IDs &lt;&gt; '0341' AND Officer_IDs &lt;&gt; 'MOB.UNIT51' AND Officer_IDs &lt;&gt; '3540' AND Date_Received &gt;= DATEADD(day, -4, GETDATE()) ORDER BY Date_Received" -o "C:\TaserExportFolder\MyData.csv" -h 852544 -s"," -w 700 -W
  </code></pre>