November 16, 2013 at 7:55 am
Hi,
I have been trying to convert the Crystal formula below into T-SQL, but I'm not able to do that. Anyone has any idea on how to convert this?
replace(space(3-len({Cono})), ' ', '1') + {Cono} +
(if len(cstr({empno}, 0, '')) < 4 then
replace(space(4-len(cstr({empno}, 0, ''))), ' ', '0')
) +
cstr({empno}, 0, '')
Thanks!
November 16, 2013 at 9:08 am
You have to use CASE instead of IF and you have to use CAST or CONVERT instead of CSTR (if it means "convert to string"). You also have to remove all of the curly braces on the column names. I don't know what the second and third operand of CSTR do but here's my best guess. It also assumes that the IF had no ELSE because I can't even spell "Crystal Formula". 😀
replace(space(3-len(Cono)), ' ', '1')
+ Cono
+ CASE
WHEN len(cstr(empno, 0, '')) < 4
THEN replace(space(4-len(CAST(empno AS VARCHAR(10)))), ' ', '0')
ELSE ''
END
+ CAST(empno AS VARCHAR(10))
--Jeff Moden
Change is inevitable... Change for the better is not.
November 18, 2013 at 8:22 am
Thank you so much. That is exactly what I wanted.
November 18, 2013 at 10:29 am
Jeff Moden (11/16/2013)
You have to use CASE instead of IF and you have to use CAST or CONVERT instead of CSTR (if it means "convert to string"). You also have to remove all of the curly braces on the column names. I don't know what the second and third operand of CSTR do but here's my best guess. It also assumes that the IF had no ELSE because I can't even spell "Crystal Formula". 😀
replace(space(3-len(Cono)), ' ', '1')
+ Cono
+ CASE
WHEN len(cstr(empno, 0, '')) < 4
THEN replace(space(4-len(CAST(empno AS VARCHAR(10)))), ' ', '0')
ELSE ''
END
+ CAST(empno AS VARCHAR(10))
Great improv Jeff, you really needed the 'crystal' ball for that one 😉
Far away is close at hand in the images of elsewhere.
Anon.
November 19, 2013 at 5:53 pm
David Burrows (11/18/2013)
Jeff Moden (11/16/2013)
You have to use CASE instead of IF and you have to use CAST or CONVERT instead of CSTR (if it means "convert to string"). You also have to remove all of the curly braces on the column names. I don't know what the second and third operand of CSTR do but here's my best guess. It also assumes that the IF had no ELSE because I can't even spell "Crystal Formula". 😀
replace(space(3-len(Cono)), ' ', '1')
+ Cono
+ CASE
WHEN len(cstr(empno, 0, '')) < 4
THEN replace(space(4-len(CAST(empno AS VARCHAR(10)))), ' ', '0')
ELSE ''
END
+ CAST(empno AS VARCHAR(10))
Great improv Jeff, you really needed the 'crystal' ball for that one 😉
I'm just glad it didn't turn out out to be too much of an as*-umption on my part.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2013 at 5:58 pm
Jysafe Lerroy (11/18/2013)
Thank you so much. That is exactly what I wanted.
You bet. Thanks for the feedback. I really don't know how to program in Crystal so I had to make some guesses. I figured if I told you what I was doing, you might be able to figure it out if I got it wrong.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply