473,416 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to convert Signed Overpunch Characters to numeric value in SQL 2005

benchpolo
142 100+
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.
Aug 24 '10 #1
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.
Aug 25 '10 #2
Jerry Winston
145 Expert 100+
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:

Expand|Select|Wrap|Line Numbers
  1. { = 0
  2. A = 1
  3. B = 2
  4. C = 3
  5. D = 4
  6. E = 5
  7. F = 6
  8. G = 7
  9. H = 8
  10. I = 9
  11. } = -0
  12. J = -1
  13. K = -2
  14. L = -3
  15. M = -4
  16. N = -5
  17. O = -6
  18. P = -7
  19. Q = -8
  20. R = -9
Aug 25 '10 #3
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?
Aug 25 '10 #4
benchpolo
142 100+
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.
Aug 25 '10 #5
NeoPa
32,556 Expert Mod 16PB
Something built around this then :
Expand|Select|Wrap|Line Numbers
  1. SELECT @Var = CAST(LEFT([Field], LEN([Field]) - 1)) * 10 + 
  2.               IF(RIGHT([Field],1) IN('{','}'), 
  3.                  0,
  4.                  IF(RIGHT([Field], 1)<'J',
  5.                     ASCII(RIGHT([Field], 1)) - ASCII('@'),
  6.                     ASCII('I') - ASCII(RIGHT([Field], 1))))
Aug 25 '10 #6
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 :
Expand|Select|Wrap|Line Numbers
  1. SELECT @Var = (CAST(LEFT([Field], LEN([Field]) - 1)) * 10 + 
  2.               IF(RIGHT([Field],1) IN('{','}'), 
  3.                  0,
  4.                  IF(RIGHT([Field], 1)<'J',
  5.                     ASCII(RIGHT([Field], 1)) - ASCII('@'),
  6.                     ASCII('I') - ASCII(RIGHT([Field], 1))))) / 100
Aug 25 '10 #7
benchpolo
142 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.
Aug 25 '10 #8
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.
Aug 25 '10 #9
Jerry Winston
145 Expert 100+
Can we just cheat and multiply by .01?:

Expand|Select|Wrap|Line Numbers
  1. SELECT 24580.0 * .01
I apologize for this shortcut ahead of time. My mental CPU is tapped trying to solve another problem.O_o
Aug 25 '10 #10
benchpolo
142 100+
multiplying to .01 works.. cheating is good for as long as I deliver the correct result lol.
Aug 25 '10 #11
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 ;)
Aug 26 '10 #12
Thanks for this code.. It helped.. me
Oct 19 '17 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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,...
2
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...
5
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...
5
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...
4
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.
13
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
12
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...
6
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...
1
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
0
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
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.