July 8, 2005 at 8:09 am
My boss has bought me this SQL Hierarchies book by CELKO you may have seen him on a discussion board. I really want to get into it but as we are using TSQL SQL2k I need to convert his examples into code I can actually use and I'm having trouble. So if anyone could convert this to TSQL or help me out in the process then I'd be much obliged. I'm ok with some of the function conversions:
create function Reverse(in instring varchar(20))
returns varchar(20)
language sql
deterministic
begin
if char_length(instring) in (0,1)
then return (instring);
else return
(Reverse(SUBSTRING (instring FROM (CHAR_LENGTH(instring)/2 + 1))
|| Reverse(SUBSTRING (instring FROM 1 FOR CHAR_LENGTH(instring)/2))));
end if;
end;
ive got this so far
CREATE FUNCTION [udf_Reverse]
(@instring varchar(20))
RETURNS varchar(20)
AS
BEGIN
if len(@instring) in (0,1) return @instring
else
return (udf_Reverse(substring(@instring, (len(@instring)/2 + 1),len(@instring)) OR udf_Reverse(substring(@instring, 1, len(@instring)/2))))
END
which is erroring with incorrect syntax near OR which I can understand as I can't see how you can return an OR statement.
But apparently the SQL/PSM is correct as its been validated so I just need some help understanding what its supposed to do so I can convert it into TSQL (if its possible!?!)
Thanks
July 8, 2005 at 8:23 am
(udf_Reverse(substring(@instring, (len(@instring)/2 + 1),len(@instring)) OR udf_Reverse(substring(@instring, 1, len(@instring)/2))))
You can't do that in tsql, you'll have to embed another if.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply