Question

I have a table (l.loandeterminationscore) that returns a result consisting of 3 #'s (XXX). I am using the below query to separate that result into a LowRange and a HighRange so that I may group the results returned into one result "XXX-XXX".

SELECT 
    l.LoanNumber,
    l.LoanDeterminationScore 'FICO', 
    FLOOR (l.LoanDeterminationScore / 20) * 20 AS LowRange,
    FLOOR (l.loanDeterminationScore / 20) * 20 + 19 AS HighRange
FROM 
    loan.LoanQA l
WHERE
    l.FundedDate = '10/15/2013'

The results returned from the above are something like this:

LoanNumber FICO LowRange HighRange
-----------------------------------
592301428  604  600      619
220300002  640  640      659
414805244  675  660      679

I'm trying to group the above FICO into a 20pt Range with the LowRange and HighRange. So in short, rather than having the two columns for the LowRange and HighRange I'd like it to return as one column showing the range as "600-619", "640-659", "660-679".

I've tried to CONCAT expression but I continually receive a "Syntax" error.

Was it helpful?

Solution

Just try this:

SELECT 
    l.LoanNumber,
    l.LoanDeterminationScore 'FICO', 
    CAST(FLOOR (l.LoanDeterminationScore / 20) * 20 AS VARCHAR(10)) + '-' +
    CAST(FLOOR (l.loanDeterminationScore / 20) * 20 + 19 AS VARCHAR(10)) AS 'Range' 
FROM 
    loan.LoanQA l
WHERE
    l.FundedDate = '10/15/2013'

Just CAST the numeric values to a string type, concatenate with +, and you're done!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top