April 2, 2014 at 10:18 pm
Hi All,
Thanks for looking in to my question.
I need a T-SQL (SQL Server) equivalent code for the PL/SQL (Oracle) query given below.
Could you help?
select sum(position_value) from
(
select power(36,position-1) * case when digit between '0' and '9'
then to_number(digit)
else 10 + ascii(digit) - ascii('A')
end
as position_value
from (
select substr(input_string,length(input_string)+1-level,1) digit,
level position
from (select '01Z' input_string from dual)
connect by level <= length(input_string)
)
)
Thanks!
Siva.
April 3, 2014 at 12:10 am
If you google around, it is easy to find the T-SQL equivalent functions. Is there anything in particular you're struggling with?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
April 3, 2014 at 4:53 am
Quick translation (Google Translate style )
;WITH NUMS(level) AS
(SELECT N FROM (VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10)) AS NM(N))
select sum(C.position_value) from
(
select
power(36,B.position-1) * case
when B.digit between '0' and '9' then CAST(B.digit AS INT)
else 10 + ascii(B.digit) - ascii('A')
end
as position_value
from
(
select
SUBSTRING(A.input_string,LEN(A.input_string)+1- dual.level,1) digit,
level position
from
(
select '01Z' AS input_string
) AS A
CROSS APPLY NUMS AS dual
WHERE level <= LEN(input_string)
) AS B
) AS C
April 3, 2014 at 6:19 am
Thanks for spending your valuable time to answer my question.
April 3, 2014 at 6:22 am
Thanks for looking into my question. I was not able to understand the usage of connect by statement. Let me try the answer given in the other reply.
April 3, 2014 at 8:37 am
Siva Ramasamy (4/3/2014)
Thanks for looking into my question. I was not able to understand the usage of connect by statement. Let me try the answer given in the other reply.
I haven't done a deep dive into the Oracle code you posted. What is it supposed to do? I ask because direct replacements between Oracle and SQL Server are frequently the worst thing that you can do on anything complex.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 3, 2014 at 9:18 am
Jeff Moden (4/3/2014)
What is it supposed to do?
It is a simple base36 to base10 number conversion.
01Z(base36) == 71 (base10)
April 3, 2014 at 9:26 am
One of my developers approached me with this query and I was not able to understand the Oracle Language.
Thanks for your help.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy