I am trying to convert a signed overpunch characters to a readable numeric value in SQL 2005. Unfortunately, I am not able to figure out the logic on how to convert it. I have never encountered this type of data before. For example,
10} is -100
45A is 451
Can someone assist me on how to write the SQL logic to convert this. I'm stuck. Your help is appreciated. Thanks.
12 17540 NeoPa 32,556
Expert Mod 16PB BenchPolo:
signed overpunch characters
What are these? Are they something you would expect everyone to know about? I certainly have no idea where this is coming from.
Do you already have the values in a table stored as character data or the like?
@NeoPa
I haven't had to work with them much but
I think this is the set of characters for signed overpunch characters: - { = 0
-
A = 1
-
B = 2
-
C = 3
-
D = 4
-
E = 5
-
F = 6
-
G = 7
-
H = 8
-
I = 9
-
} = -0
-
J = -1
-
K = -2
-
L = -3
-
M = -4
-
N = -5
-
O = -6
-
P = -7
-
Q = -8
-
R = -9
NeoPa 32,556
Expert Mod 16PB
Thanks Jerry.
Can I ask why only the last digit is indicated by an SOC?
Will it always be only the units that are designated that way?
This is an old technology, and one of our vendor is passing this value to us (see reference below)
Code Digit Sign
---- ----------- ----
} 0 -
J 1 -
K 2 -
L 3 -
M 4 -
N 5 -
O 6 -
P 7 -
Q 8 -
R 9 -
{ 0 +
A 1 +
B 2 +
C 3 +
D 4 +
E 5 +
F 6 +
G 7 +
H 8 +
I 9 +
I was able to write a logic surrounding the conversion of the signed overpunch characters
case when right(total_amount_paid_by_all_sources,1) = '}' then '-' + left(total_amount_paid_by_all_sources,7) + '0'
when right(total_amount_paid_by_all_sources,1) = 'J' then '-' + left(total_amount_paid_by_all_sources,7) + '1'
when right(total_amount_paid_by_all_sources,1) = 'K' then '-' + left(total_amount_paid_by_all_sources,7) + '2'
when right(total_amount_paid_by_all_sources,1) = 'L' then '-' + left(total_amount_paid_by_all_sources,7) + '3'
when right(total_amount_paid_by_all_sources,1) = 'M' then '-' + left(total_amount_paid_by_all_sources,7) + '4'
when right(total_amount_paid_by_all_sources,1) = 'N' then '-' + left(total_amount_paid_by_all_sources,7) + '5'
when right(total_amount_paid_by_all_sources,1) = 'O' then '-' + left(total_amount_paid_by_all_sources,7) + '6'
when right(total_amount_paid_by_all_sources,1) = 'P' then '-' + left(total_amount_paid_by_all_sources,7) + '7'
when right(total_amount_paid_by_all_sources,1) = 'Q' then '-' + left(total_amount_paid_by_all_sources,7) + '8'
when right(total_amount_paid_by_all_sources,1) = 'R' then '-' + left(total_amount_paid_by_all_sources,7) + '9'
when right(total_amount_paid_by_all_sources,1) = '{' then left(total_amount_paid_by_all_sources,7) + '0'
when right(total_amount_paid_by_all_sources,1) = 'A' then left(total_amount_paid_by_all_sources,7) + '1'
when right(total_amount_paid_by_all_sources,1) = 'B' then left(total_amount_paid_by_all_sources,7) + '2'
when right(total_amount_paid_by_all_sources,1) = 'C' then left(total_amount_paid_by_all_sources,7) + '3'
when right(total_amount_paid_by_all_sources,1) = 'D' then left(total_amount_paid_by_all_sources,7) + '4'
when right(total_amount_paid_by_all_sources,1) = 'E' then left(total_amount_paid_by_all_sources,7) + '5'
when right(total_amount_paid_by_all_sources,1) = 'F' then left(total_amount_paid_by_all_sources,7) + '6'
when right(total_amount_paid_by_all_sources,1) = 'G' then left(total_amount_paid_by_all_sources,7) + '7'
when right(total_amount_paid_by_all_sources,1) = 'H' then left(total_amount_paid_by_all_sources,7) + '8'
when right(total_amount_paid_by_all_sources,1) = 'I' then left(total_amount_paid_by_all_sources,7) + '9'
end as convert1
The dilemma that i'm having now is converting the value to a 2 decimal places (see below)
Signed overpunch 0002458{ converted value 24580.0. It should be 245.80. Can you help? Thanks.
NeoPa 32,556
Expert Mod 16PB
Something built around this then : - SELECT @Var = CAST(LEFT([Field], LEN([Field]) - 1)) * 10 +
-
IF(RIGHT([Field],1) IN('{','}'),
-
0,
-
IF(RIGHT([Field], 1)<'J',
-
ASCII(RIGHT([Field], 1)) - ASCII('@'),
-
ASCII('I') - ASCII(RIGHT([Field], 1))))
NeoPa 32,556
Expert Mod 16PB
I've just caught your latest post (#5). The change should be pretty trivial :
Something built around this then : - SELECT @Var = (CAST(LEFT([Field], LEN([Field]) - 1)) * 10 +
-
IF(RIGHT([Field],1) IN('{','}'),
-
0,
-
IF(RIGHT([Field], 1)<'J',
-
ASCII(RIGHT([Field], 1)) - ASCII('@'),
-
ASCII('I') - ASCII(RIGHT([Field], 1))))) / 100
I already converted the signed overpunch characters to its corresponding numeric value. I need assistance though in converting it to 2 decimal places.
from 24580.0 It should be 245.80. Can you help? Thanks.
NeoPa 32,556
Expert Mod 16PB
Well, (a bit confused) what I did was divide the result by 100. If you find that complicated with your code then perhaps your code could do with some looking at. Alternatively, you could simply use the 6 lines of code I posted to do the whole job. Your choice of course.
Can we just cheat and multiply by .01?:
I apologize for this shortcut ahead of time. My mental CPU is tapped trying to solve another problem.O_o
multiplying to .01 works.. cheating is good for as long as I deliver the correct result lol.
NeoPa 32,556
Expert Mod 16PB
Well, I'm glad that multiplying by 0.01 worked. Shame dividing by 100 doesn't seem to have done the job ;)
Thanks for this code.. It helped.. me
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Arnold Shore |
last post by:
I need access to the bits of a Byte expression, and the logical functions
operatge bit-wise on numeric vales - per the VBScript CHM.
So how do I convert a Byte to its numeric value?
Thanks,...
|
by: Iona |
last post by:
okay.. this should be long..
I made up a table in database with access consists of columns with text type. Some of them I put in data with numeric value and some of them I put in "Unlimited" as...
|
by: ief |
last post by:
hi all,
i'm trying to check the length of a numeric value in a string.
this is what i need to do:
I have a string "Mystring (253)"
and a string "SecondString (31548745754)"
Now i have to...
|
by: Joergen Bech |
last post by:
Basically, I want to convert hex values in the range
"00000000" to "FFFFFFFF" to a signed, 32-bit Integer
value.
In VB6, I could just write lngValue = Val(hexstring$).
In VB.Net, I seem to be...
|
by: Surek |
last post by:
I need to get the numeric value alone in a string which includes special characters and alphabets.
eg string: vism/t1-1/1
Should retrieve the first numeric value from the given string.
|
by: nishit.gupta |
last post by:
Is their any fuction available in C++ that can determine that a string
contains a numeric value.
The value cabn be in hex, int, float. i.e. "1256" , "123.566" ,
"0xffff"
Thnx
|
by: Ahmad Jalil Qarshi |
last post by:
Hi,
I have an integer value which is very long like 9987967441778573855.
Now I
want to convert it into equivalent Hex value.
The result must be 8A9C63784361021F
I have used...
|
by: frohlinger |
last post by:
Hi,
I need to perform some numeric calculations on a numeric float value,
that is received as wstring.
I would like to perform a check before converting the wstring to
float, checking that indeed...
|
by: Jarosław Kozik |
last post by:
How to formatting numeric value like 20,5 to money value like 20,50 USD
using MS SQL server 2000
regards IJKK
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |