Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Summarizing data in final row
    primarykey
    data
    text
    <p>I have a query that generates rows of detail information about checks that are issued. In the final output, the data is all concatenated and put into one column (long story short, it needs to be run from Infomaker and exported to text with no delimiting). </p> <p>Anyway, at the end of these rows I need a summary row that contains two values that are sums of the detail used in the previous rows, along with other values that are hard-coded. This final row also needs to be concatenated to one column, and appear after all the detail rows.</p> <p>Example of how the summary row should appear with the computed values in brackets:</p> <pre><code>00123456789999999999940[CHECK AMOUNT SUMMARY][TOTAL NUMBER OF CHECKS (ROWS)]000 </code></pre> <p>Again, no spaces, tabs, or any other delimiters allowed.</p> <p>I'm stumped on how to achieve this. I have had suggestions of using UNION but I'm not sure exactly how to make that work for this situation.</p> <p>Current query:</p> <pre><code>declare @checkDate date = '08/30/13' select record = ( -- Checking account number (Record positions 1-9) cast(cna.BANK_ACCT_NUM as varchar(9)) + -- Check number (Record positions 10-19) -- must always be nine characters (case when LEN(cr.CHECK_NUM_NUMERIC) = 1 then '00000000' when LEN(cr.CHECK_NUM_NUMERIC) = 2 then '0000000' when LEN(cr.CHECK_NUM_NUMERIC) = 3 then '000000' when LEN(cr.CHECK_NUM_NUMERIC) = 4 then '00000' when LEN(cr.CHECK_NUM_NUMERIC) = 5 then '0000' when LEN(cr.CHECK_NUM_NUMERIC) = 6 then '000' when LEN(cr.CHECK_NUM_NUMERIC) = 7 then '00' when LEN(cr.CHECK_NUM_NUMERIC) = 8 then '0' else '' end + cast(cr.CHECK_NUM_NUMERIC as varchar(9))) + -- Record positions 20-21 - as determined by the bank '20' + -- Check amount (Record positions 22-31) -- must always be 10 characters (case when LEN(cr.CHECK_AMT) = 1 then '000000000' when LEN(cr.CHECK_AMT) = 2 then '00000000' when LEN(cr.CHECK_AMT) = 3 then '0000000' when LEN(cr.CHECK_AMT) = 4 then '000000' when LEN(cr.CHECK_AMT) = 5 then '00000' when LEN(cr.CHECK_AMT) = 6 then '0000' when LEN(cr.CHECK_AMT) = 7 then '000' when LEN(cr.CHECK_AMT) = 8 then '00' when LEN(cr.CHECK_AMT) = 9 then '0' else '' end + cast(REPLACE(cr.CHECK_AMT,'.','') as varchar(10))) + -- Date issued (MMDDYY)(Record positions 32-37) cast(REPLACE(convert(char(10),cr.CHECK_DTE,101), '/', '') as varchar(10)) + -- Record positions 38-40 - as determined by the bank '000' + -- Payee information line 1 (Record positions 41-90) cr.CHECK_NAME) from chk_num_alpha_ctl cna, chk_reconciliation cr where ( cr.check_num_alpha = cna.check_num_alpha ) and ( ( cr.check_rtn_void_dte is null ) AND ( cr.check_dte = @checkDate ) ) AND ( cna.bank_acct_num = 'xxxx-xxxx' ) order by cr.check_dte ASC </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload