May 25, 2014 at 7:32 am
Hi,
I have this code
SELECT
b.TransDate, b.TransType, b.SortCode, b.AccNum, b.TransDesc, b.Debit, b.Credit,
(ISNULL(b.Debit, 0) + ISNULL (b.Credit, 0)) as Amount,
ISNULL(r.OrthoID, 'Need ID') as OrthoID
FROM
EPSBankTransactions b
LEFT JOIN EPSBankRef r on b.TransDesc = r.BankID
but I would only like to try a join on the first 20 characters of b.TransDesc and not the full string. I'm not sure how I would best do that.
thanks
May 25, 2014 at 7:42 am
sorted it out, didn't think it would work for some reason but
LEFT JOIN EPSBankRef r on SUBSTRING(b.TransDesc, 0, 21) = r.BankID
does the job.
May 25, 2014 at 10:08 am
Realize that you lose any benefits of having an index on the TransDesc column. If you can, you may want to consider adding a persisted computed column that stores the first 20 characters of the TransDesc column (LEFT(TransDesc,20)) and build an index on that column.
May 25, 2014 at 10:12 am
Lynn Pettis (5/25/2014)
Realize that you lose any benefits of having an index on the TransDesc column. If you can, you may want to consider adding a persisted computed column that stores the first 20 characters of the TransDesc column (LEFT(TransDesc,20)) and build an index on that column.
+1000
But to add to Lynn's good suggestionn, an even better option would be to normalize the data instead of having more than one piece of information in a single column.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 25, 2014 at 10:15 am
Jeff Moden (5/25/2014)
Lynn Pettis (5/25/2014)
Realize that you lose any benefits of having an index on the TransDesc column. If you can, you may want to consider adding a persisted computed column that stores the first 20 characters of the TransDesc column (LEFT(TransDesc,20)) and build an index on that column.+1000
But to add to Lynn's good suggestionn, an even better option would be to normalize the data instead of having more than one piece of information in a single column.
another +1000 here
Normalizing the data would be a very good thing.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply