Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to transpose row values to one column formatted as 999999999999 using SQL 2008?

Status
Not open for further replies.

makeitwork09

Technical User
Sep 28, 2009
170
US
We have SQL 2008. We were supposed to go live with SQL 2016 at the end of March. That got put on hold when we started working from home the beginning of March.

I am helping to fulfill a requirement for a dated ump.

One of the fields requires that we show the results formatted as 999999999999. That's 12 9s.

The 9s are to be replaced with the number of months delinquent in the past 12 months. So each 9 represents one of the 12 months.

The table reads like a table should reading row by row with columns of loan, due date, and paid date. I calculate the number of months using
SQL:
DATEDIFF(month, due_date, inst_paid_date)

and the where clause has

SQL:
due_date between DATEADD(month, -12, l.accounting_date) and '2020-04-01')


Note, not every loan has payment due information going back 12 months. That is because loans close at different times throughout the year, but I still need to show the information as 999999999999.

So if we had a loan during the course of the 12 month period, with a payment a month late in March would look like the following"
0
0
1
0
0
0
0
0
0
0
0
0

I need to show it as 001000000000.

And if the loan closed in December of last year, it would only have payment records for three months, Jan, Feb, and Mar. Let's say there are no late payments. The results would be as follows for the past 12 months starting with 4/1/2020:

0
0
0

But I need to show the results as follows:

000000000000.

How can I accomplish that using SQL 2008?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top