title: How to save SQL query results to tab delimited text file
body: <p>I'm using the following SQL script to generate 4 output queries.  I would like to know if there is a way to save the results directly to a tab text delimited file.  </p>
  
  <p>For example: <code>SELECT * FROM &lt;table&gt; Export TO "C:\TEMP\Output.txt"</code></p>
  
  <p>Thanks</p>
  
  <pre><code>DECLARE @DLNK_POS As TABLE
  (
      TERMINAL int,
      OPERATOR int,
      TRANSNUM int,
      SEQNUM int,
      STORE_NO int,
      DL_NO int,
      DL_SDATE date,
      DL_EDATE date,
      POS_DATE date,
      PALLET varchar(1),
      ODS varchar(1),
      UPC bigint,
      PACK int,
      SIZE varchar(10),
      ITEM_DESC varchar(40),
      P_BB_AMT decimal(10,2),
      S_BB_AMT decimal(10,2),
      SOLD_QTY int,
      PRICE money,
  );
  
  
  WITH [CTE] As
  (
      SELECT
          F1.TERMINAL,
          F1.OPERATOR,
          F1.TRANS_NO,
          F1.SEQ_NO,
          F1.STORE_NO,
          FDL.DL_NO,
          FDL.DL_SDATE1,
          FDL.DL_EDATE1,
          F1.POS_DATE,
          FDL.PALLET,
          FDL.ODS,
          F1.UPC,
          FDL.DL_PACK,
          FDl.DL_SIZE,
          FDL.DL_ITEM_DESC,
          FDL.P_BB_AMT,
          FDL.S_BB_AMT,
          F1.QTY,
          F1.PRICE,
      FROM [MSTR_DB].[dbo].[POS] As F1
      INNER JOIN [MSTR_DB].[dbo].[DEAL] As FDL
      ON (F1.UPC = FDL.DL_UPC)  And (F1.POS_DATE BETWEEN FDL.DL_SDATE1 And FDL.DL_EDATE1) And FDL.S_BB_AMT != 0
  )
  
  INSERT  INTO @DLNK_POS SELECT * FROM [CTE];
  </code></pre>
  
  <blockquote>
    <p>/<strong>* OUTPUT 1 *</strong>/ SELECT * FROM @DLNK_POS;</p>
    
    <p>/<strong>* OUTPUT 2 *</strong>/ SELECT DL_NO, DL_SDATE, DL_EDATE, PALLET, ODS,
    STORE_NO, PACK, SIZE, UPC, ITEM_DESC, P_BB_AMT, S_BB_AMT,
    SUM(SOLD_QTY) As SOLD_QTY FROM @DLNK_POS GROUP BY DL_NO, DL_SDATE,
    DL_EDATE, PALLET, ODS, STORE_NO, PACK, SIZE, UPC, ITEM_DESC, P_BB_AMT,
    S_BB_AMT ORDER BY DL_NO, STORE_NO, UPC;</p>
    
    <p>/<strong>* OUTPUT 3 *</strong>/ SELECT DL_NO, DL_SDATE, DL_EDATE, STORE_NO,
    SUM(SOLD_QTY) As SQL_QTY FROM @DLNK_POS GROUP BY DL_NO, DL_SDATE,
    DL_EDATE, STORE_NO ORDER BY DL_NO, STORE_NO</p>
    
    <p>/<strong>* OUTPUT 4 *</strong>/ SELECT DL_NO, DL_SDATE, DL_EDATE, PALLET, ODS,
    PACK, SIZE, UPC, ITEM_DESC, P_BB_AMT, S_BB_AMT, SUM(SOL_QTY) As
    SOLD_QTY FROM @DLNK_POS GROUP BY DL_NO, DL_SDATE, DL_EDATE, PALLET,
    ODS, PACK, SIZE, UPC, ITEM_DESC, P_BB_AMT, S_BB_AMT;</p>
  </blockquote>