Reputation: 69
Here I have query for select the first and last query.
SELECT MAX(invoiceNo) AS MaxInvoiceNo, MIN(invoiceNo) AS MinInvoiceNo FROM JobInvoice
My question is how I'm gonna fix this to put dash ( - ) between that MAX(invoiceNo)
and MIN(invoiceNo)
. Just like MAX(invoiceNo)- MIN(invoiceNo)
Upvotes: 0
Views: 88
Reputation: 69
It work from Gordon's help. Here I add a bit.
SELECT RTRIM(MAX(invoiceNo)) + ' - ' + MIN(invoiceNo) AS InvoiceRange FROM JobInvoice
Output like
Upvotes: 0
Reputation: 1269643
You can just concatenate them. If the values are strings:
SELECT LTRIM(RTRIM(MAX(invoiceNo))) + '-' + LTRIM(RTRIM(MIN(invoiceNo))) AS InvoiceRange
FROM JobInvoice;
If not, you need to cast them:
SELECT CONVERT(VARCHAR(255), MAX(invoiceNo)) + '-' + CONVERT(VARCHAR(255), MIN(invoiceNo)) AS InvoiceRange
FROM JobInvoice;
Upvotes: 1