The code below does not seem to work when the value is '0000004000' it is returning a value of 4.00 instead of 40.00. Can someone please advise how to convert '0000004000' to 40.00.
Thanks.
Code: - DECLARE @i int
-
, @temp char(1), @tmp varchar(1), @a varchar(1)
-
, @ebcdic char(2)
-
, @result VARCHAR(255) , @result1 numeric(22,2)
-
-
SET @i=1
-
SET @result=''
-
set @a ='0'
-
-
WHILE (@i<=LEN(@s))
-
BEGIN
-
-
SET @temp=SUBSTRING(@s,@i,1)
-
SET @tmp=SUBSTRING(@s,@i,1)
-
-
SET @ebcdic=CASE @temp
-
-
--POSITIVE
-
WHEN '{' THEN '0'
-
WHEN 'A' THEN '1'
-
WHEN 'B' THEN '2'
-
WHEN 'C' THEN '3'
-
WHEN 'D' THEN '4'
-
WHEN 'E' THEN '5'
-
WHEN 'F' THEN '6'
-
WHEN 'G' THEN '7'
-
WHEN 'H' THEN '8'
-
WHEN 'I' THEN '9'
-
-
--NEGATIVE
-
-
WHEN '}' THEN '0'
-
WHEN 'J' THEN '1'
-
WHEN 'K' THEN '2'
-
WHEN 'L' THEN '3'
-
WHEN 'M' THEN '4'
-
WHEN 'N' THEN '5'
-
WHEN 'O' THEN '6'
-
WHEN 'P' THEN '7'
-
WHEN 'Q' THEN '8'
-
WHEN 'R' THEN '9'
-
ELSE ' '
-
-
END
-
-
SET @a =CASE @tmp
-
--NEGATIVE
-
WHEN '}' THEN '1'
-
WHEN 'J' THEN '1'
-
WHEN 'K' THEN '1'
-
WHEN 'L' THEN '1'
-
WHEN 'M' THEN '1'
-
WHEN 'N' THEN '1'
-
WHEN 'O' THEN '1'
-
WHEN 'P' THEN '1'
-
WHEN 'Q' THEN '1'
-
WHEN 'R' THEN '1'
-
ELSE '0'
-
-
END
-
-
IF @ebcdic=''
-
-
SET @ebcdic=CASE
-
-
WHEN ASCII(@temp) BETWEEN 129 AND 137 THEN CHAR(ASCII(@temp)-32)
-
WHEN ASCII(@temp) BETWEEN 145 AND 153 THEN CHAR(ASCII(@temp)-39)
-
WHEN ASCII(@temp) BETWEEN 162 AND 169 THEN CHAR(ASCII(@temp)-47)
-
WHEN ASCII(@temp) BETWEEN 193 AND 201 THEN CHAR(ASCII(@temp)-128)
-
WHEN ASCII(@temp) BETWEEN 209 AND 217 THEN CHAR(ASCII(@temp)-135)
-
WHEN ASCII(@temp) BETWEEN 226 AND 233 THEN CHAR(ASCII(@temp)-143)
-
WHEN ASCII(@temp) BETWEEN 240 AND 249 THEN CHAR(ASCII(@temp)-192)
-
-
ELSE ''
-
-
END
-
SET @result=@result+@ebcdic
-
SET @i=@i+1
-
END
-
-
set @result1 = convert(numeric,(case when @a ='1' then '-' else '+' end + substring( @s, 1,len(@s)-1) + ltrim(rtrim(@result))))
-
RETURN @result1/100
-
END
8 6632
What does your code trying to do? It would easier for us to recommend either a fix or a new technique.
Good Luck!!!
~~ CK
It is trying to convert an overpunch character on the data that we receive for positive or negative .. so if 000000400} is received the function will convert it to -40.00 bec. of "}" character. Our vendor somehow decided to provide overpunch characters on the negative value and not on the zero positive value.
Sure, I'm always open for new suggestion.
Thanks
Is the "}" character fixed for negative values? Are there any other character used? If it's positive, do they put in any other character identifier? Could you post some sample (maybe 10?) rows of positive and negative numbers and how it will be converted to?
~~ CK
It is a total of 10 length and the last digit is always and overpunch..
000000400}
000000400{
000000500A
000000500J
000000600C
000000600L
000000310E
000000311N
000000222I
000000222R
Thanks.
but when the value is not an overpunch such as 0000004000 it should be as is like 40.00
So, based on the sample you posted, what would be the equivalent converted value? Are those all positives and only the first one as negative?
~~ CK
THe negatives are okay because they are being converted throught the posted sql function script. It is when it encounters a zero "0" if its zero then it should take the as is value since the vendor does not provide the "{" overpunch value. So if the value of the field has an overpunch character at the end then convert it accordingly else take the value as is.. make sense?
Thanks ck!
It looks to me like a straight-forward string manipulation. If I understand it right, you don't need a character by character parsing, just parse the rightmost. Try this script. It is based on your sample data. -
-
select
-
yourvalue,
-
parsed =
-
substring(yourvalue, 1, len(yourvalue)-1) +
-
case
-
when right(yourvalue,1) in ('{','}','0') then '0'
-
when right(yourvalue,1) between 'A' and 'I' then cast(ascii(right(yourvalue,1))-64 as char(1))
-
when right(yourvalue,1) between 'J' and 'R' then cast(ascii(right(yourvalue,1))-73 as char(1))
-
else ''
-
end,
-
factor =
-
case
-
when right(yourvalue,1) in ('{','0') or right(yourvalue,1) between 'A' and 'I' then 1
-
when right(yourvalue,1) in ('}') or right(yourvalue,1) between 'J' and 'R' then -1
-
end,
-
converted =
-
(cast(
-
substring(yourvalue, 1, len(yourvalue)-1) +
-
case
-
when right(yourvalue,1) in ('{','}','0') then '0'
-
when right(yourvalue,1) between 'A' and 'I' then cast(ascii(right(yourvalue,1))-64 as char(1))
-
when right(yourvalue,1) between 'J' and 'R' then cast(ascii(right(yourvalue,1))-73 as char(1))
-
else ''
-
end
-
as int) *
-
case
-
when right(yourvalue,1) in ('{','0') or right(yourvalue,1) between 'A' and 'I' then 1
-
when right(yourvalue,1) in ('}') or right(yourvalue,1) between 'J' and 'R' then -1
-
end) / 100.00
-
from
-
(
-
select yourvalue = '000000400}'
-
union all
-
select '000000400{'
-
union all
-
select '000000500A'
-
union all
-
select '000000500J'
-
union all
-
select '000000600C'
-
union all
-
select '000000600L'
-
union all
-
select '000000310E'
-
union all
-
select '000000311N'
-
union all
-
select '000000222I'
-
union all
-
select '000000222R'
-
union all
-
select '0000004000'
-
) yourdata
-
The "union all" sub-query was created just to create a sample data set. The four columns will show the value based on your sample data; the parsed value with the overpunch character converted, just so you can check if the letter-to-number conversion is correct; the sign converter (positive or negative); and the converted-to-integer value...
If you're going to convert this into a function, the only portion you need is the formula for the "converted" column.
Good Luck!!!
~~ CK
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rudolf Horbas |
last post by:
Hi all,
in a string from a form post, I sometimes get characters like ő
(õ) as raw data (not masked). ( "Å‘", if Your mail program
supports this).
It appears that Mozilla converts the...
|
by: Kamal |
last post by:
PHP 4.3.4 on Apache 2.0.48 on Linux Red Hat 8.0 Kernel 2.4.18-14smp
with Oracle 9iR2.
I have this code:
<html>
<body>
<?php
|
by: Scott |
last post by:
I am using DB2 Connect on HP-UX 11i to read data from an AS400 using
SQL. DB2 Connect is converting a vertical bar (¦) character to this:
ª. Please see the example below. I have tried changing the...
|
by: Kasper Hansen |
last post by:
I need to search through a binary file to find a specific string and then
replace it with another string. However the
System.Text.Encoding.ASCII.GetString method i originally used seems to do
some...
|
by: Ernie Otero |
last post by:
Does anyone know where I can find a function to convert numeric data to
overpunch format? I've looked around but I can't seem to find any.
Ernie
|
by: Lucky |
last post by:
Hi Guys!!!
i'm newbie to asp.net 2.0. i've got a problem. i've a textfield on my
webpage and if i insert " can't " or " test - test " value into it and
post it back the " ' " and " - " get...
|
by: saul.baizman |
last post by:
Here's a brief description of the problem. My organization has a
client who cuts and pastes information from Microsoft Word documents
into web-based forms, whose contents is then displayed on a...
|
by: DaveP |
last post by:
hi i want to convert say letter A to its Ascii Value and back to its
Character Value..
im cant Seem To Find how to do this
Tks
DaveP
|
by: =?Utf-8?B?UGhhbmlkaGFy?= |
last post by:
Hi,
I'm developing a Winform application in C#( .net 2.0). I've a dialog box
where user can input text and that text would be sent across to other machine
using sockets.
When the user enters...
|
by: amollokhande1 |
last post by:
Hi All,
I want to build an application that will convert the english characters into other languages like Chinees, Japanies etc using VB.net. I am looking for use of Double byte character set for...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |