How can I improve this code by using variables for FirstSpace and NextSpace? It works as is - I just am trying to learn something.
Thanks,
Gladys
Gladys Clemmer
gladys.clemmer@fifsg.com
Code:
SELECT Space(13)+[CUS-LOAN] AS ACCOUNT,
Right("0000000000" + cast([FIC-AMT-PAST-DUE]*100 as varchar),10) AS AMOUNT_DUE,
[FIC-SOCSEC] AS SSN,
CHARINDEX(space(1), [FIC-NAM1]) AS FirstSpace,
CHARINDEX(space(1),[FIC-NAM1], CHARINDEX(space(1),[FIC-NAM1])+1) AS NextSpace,
[FIC-NAM1],
Left(Left([FIC-NAM1],CHARINDEX(space(1),[FIC-NAM1])-1)+ Space(16),16) AS FirstName,
CASE
WHEN CHARINDEX(space(1),[FIC-NAM1], CHARINDEX(space(1),[FIC-NAM1])+1) = 0 THEN
LEFT(LTrim(Substring([FIC-NAM1],CHARINDEX(space(1),[FIC-NAM1])+1,30)+ space(30)), 30)
WHEN CHARINDEX(space(1),[FIC-NAM1], CHARINDEX(space(1),[FIC-NAM1])+1) <> 0 THEN
LEFT(LTrim(Substring([FIC-NAM1],CHARINDEX(space(1),[FIC-NAM1], CHARINDEX(space(1),[FIC-NAM1])+1),30)+ Space(30)),30)
END AS LastName,
Left([FIC-NAM3] + Space(30),30) AS Address, Space(30) AS ADDRESS2, [FIC-NAM5],
Right(LTrim(RTrim([FIC-NAM5])),2) AS STATE,
Left(Left([FIC-ZIP],5) + "-" + Substring([FIC-ZIP],6,4) + "0000",10) AS ZIPCODE, [FIC-CLOS]
FROM ShawMiniMaster_Current
WHERE [FIC-CLOS]='0'
Gladys
Gladys Clemmer
gladys.clemmer@fifsg.com