novice12
asked on
String Operations in SQL
Experts!!
I am using SQL 2000
I have a table called "MyTable" with a column called "hexcode". The data type is nvarchar (in a form of hex string).
The data looks some thing like this: 371D8041
I need a function that would re-arrange the above string so it looks like this: 41801D37
So basically I want to reverse the order of pair of charcters.
I am doing this:
select
Lo1+Lo2+Lo3+Lo4 as ActualCode
from
(
select
Substring(Hexcode,7,2) Lo1, Substring(Hexcode,5,2) Lo2, Substring(Hexcode, 3,2) Lo3, Substring(Hexcode,1,2) Lo4
from
MyTable
)
as T1
The above query works, but I need to write it as a function. This way I don't have to repeat the code every time.
How would I do this? Thanks
I am using SQL 2000
I have a table called "MyTable" with a column called "hexcode". The data type is nvarchar (in a form of hex string).
The data looks some thing like this: 371D8041
I need a function that would re-arrange the above string so it looks like this: 41801D37
So basically I want to reverse the order of pair of charcters.
I am doing this:
select
Lo1+Lo2+Lo3+Lo4 as ActualCode
from
(
select
Substring(Hexcode,7,2) Lo1, Substring(Hexcode,5,2) Lo2, Substring(Hexcode, 3,2) Lo3, Substring(Hexcode,1,2) Lo4
from
MyTable
)
as T1
The above query works, but I need to write it as a function. This way I don't have to repeat the code every time.
How would I do this? Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.