Solved

Totals for footer sql server query

Posted on 2008-06-23
7
250 Views
Last Modified: 2010-04-21
below is my working query thus far.

I am missing a final piece which is a select with special concantonation in front of the current final select to ADD all the CHECK NUMBERS together in otherwords check number 1003, 1002, 1000, and 1001 would show in the result as 0000004006
Also - right now with the current code (working) my bottom line of output is  
000000624168510

so now with the example I gave it would read like this:

0000004006000000624168510
Then if there were 4 checks (as in the example it will appear:

                                       
1EOF 00004                    00000040060624168510

finally - THE TRAILING ZERO ON 00000040060624168510 NEEDS TO MOVE AT THE END OF THE CHECK NUMBERS ADDED TOGETHER THUS

1EOF 00004                    00000040060062416851

I wish I could assign DOUBLE TRIPLE etc points for this but I can't  Thank you so much IN ADVANCE :)
use [stvfin]
select lines
from(
select top 1 '1' as line_seq,'DRS355008765102873' + convert(varchar(10), getdate(), 112) + convert(varchar(10), getdate(), 112) + 'N'  as Lines
from cashmgmt_payment
WHERE record_identity='0000QVSVS7KL'
 
union all
 
select top 100 percent '2',right('0000000000' + cast(payment_id as varchar(10)),10) +
       right('0000000000' + replace(cast(amount as varchar(10)),'.',''),10) + '3558765102873' as result
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
and payment_method_id = 'CHECK'
and amount >0.00
and  record_created > '20080620'
 
union all
 
select '3',right('000000000000000' + (replace(cast(sum(amount) as varchar(15)),'.','') ),15)
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
  and payment_method_id = 'CHECK'
  and amount >0.00
  and record_created > '20080620'
) as c
0
Comment
Question by:MyDanes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:MyDanes
ID: 21849240
by the way This is for a export to Bank of America - the expert (Mark Willis) who helped me with another problem on this project pointed out that it does make a difference for what I am trying to do ;)

Thanks in advance.
0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 21849445
Think this should go close... It is really just the footer / last bit.
select lines
from(
select top 1 '1' as line_seq,'DRS355008765102873' + convert(varchar(10), getdate(), 112) + convert(varchar(10), getdate(), 112) + 'N'  as Lines 
from cashmgmt_payment 
WHERE record_identity='0000QVSVS7KL'
 
union all
 
select top 100 percent '2',right('0000000000' + cast(payment_id as varchar(10)),10) + 
       right('0000000000' + replace(cast(amount as varchar(20)),'.',''),10) + '3558765102873' as result
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
and payment_method_id = 'CHECK'
and amount >0.00
and  record_created >'20080105'
order by record_created DESC
 
union all
 
select '3','1EOF '+right('00000'+convert(varchar,count(distinct payment_id)),5)
+'                   '
+right('0000000000'+convert(varchar,sum(payment_id)),10)
+right('0000000000' + (replace(cast(sum(amount) as varchar(20)),'.','') ),1)
+substring(right('0000000000' + (replace(cast(sum(amount) as varchar(20)),'.','') ),10),1,9)
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
  and payment_method_id = 'CHECK'
  and amount >0.00
  and record_created >'20080105'
) as c
order by line_seq

Open in new window

0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 21849462
Taht was assuming that payment_id is the same as check numbers or cheques as I know them :)
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:MyDanes
ID: 21849957
You are right payment_id is the check (cheque) number but I am getting this error:

Msg 409, Level 16, State 2, Line 2
The sum or average aggregate operation cannot take a varchar data type as an argument.
0
 
LVL 51

Accepted Solution

by:
Mark Wills earned 500 total points
ID: 21851637
Ahhh... In my little test database it is a Numeric field !

That makes it a little more challenging...
select lines
from(
select top 1 '1' as line_seq,'DRS355008765102873' + convert(varchar(10), getdate(), 112) + convert(varchar(10), getdate(), 112) + 'N'  as Lines 
from cashmgmt_payment 
WHERE record_identity='0000QVSVS7KL'
 
union all
 
select top 100 percent '2',right('0000000000' + cast(payment_id as varchar(10)),10) + 
       right('0000000000' + replace(cast(amount as varchar(20)),'.',''),10) + '3558765102873' as result
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
and payment_method_id = 'CHECK'
and amount >0.00
and  record_created >'20080105'
order by record_created DESC
 
union all
 
select '3','1EOF '+right('00000'+convert(varchar,count(distinct payment_id)),5)
+'                   '
+right('0000000000'+convert(varchar,sum(case when isnumeric(isnull(payment_id,'0')) > 0 then convert(int,payment_id) else 0 end)),10)
+right('0000000000' + (replace(cast(sum(amount) as varchar(20)),'.','') ),1)
+substring(right('0000000000' + (replace(cast(sum(amount) as varchar(20)),'.','') ),10),1,9)
from CASHMGMT_PAYMENT
where bank_account_id='BOA'
  and payment_method_id = 'CHECK'
  and amount >0.00
  and record_created >'20080105'
) as c
order by line_seq

Open in new window

0
 

Author Comment

by:MyDanes
ID: 21859551
OUTSTANDING - thanks Mark

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_23512309.html

that is THE LAST new question for this project which was not encompassed in this issue (which you have resolved) :)

I would LOVE if you could help me with the last piece of the problem

Have a GREAT day.
0
 

Author Closing Comment

by:MyDanes
ID: 31469894
UNBELIEVABLE  AAAAAA+++++++

would assign 10k points if I could to this - it was TOUGH :)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question