473,468 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inserting two spaces into a char(8), DB2 omits a space

Here's the question:
How do you get DB2 to update a char(n) field with multiple spaces right
next to each other without having the additional spaces being omitted?

Here's the background:
We have a field "codes2" that's defined as char(8) that we use to keep
eight different codes (i.e. codes2[0] = something, codes2[1] =
something else, etc.). I'm sure that idea is nothing new to anyone but
our problem arises when we try to store two spaces (' ') right next to
each other.

This command:

EXEC SQL UPDATE TBLNAME SET CODES2 = '5H 7B3d' WHERE ...;

Completes without errors but when you look in the table to see what was
actually done, codes2 = '5H 7B3d', the DB2 just decided to omit one of
the spaces and slide the rest of the string over. You can imagine our
problem when we've got programs looking for the value in codes2[3] and
instead of finding a space (' ') it finds a 7...not good.

Nov 12 '05 #1
4 1653
I took a peek and did not find a problem. Could you try the following
code?

DECLARE GLOBAL TEMPORARY TABLE A (A CHAR(8))
INSERT INTO SESSION.A VALUES('5H 7B3d')
SELECT 1, '==>' || SUBSTR(A, 1, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 2, '==>' || SUBSTR(A, 2, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 3, '==>' || SUBSTR(A, 3, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 4, '==>' || SUBSTR(A, 4, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 5, '==>' || SUBSTR(A, 5, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 6, '==>' || SUBSTR(A, 6, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 7, '==>' || SUBSTR(A, 7, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 8, '==>' || SUBSTR(A, 8, 1) || '<==' FROM SESSION.A ORDER BY 1

UPDATE TBLNAME SET A = '5H 7B3d'

SELECT 1, '==>' || SUBSTR(A, 1, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 2, '==>' || SUBSTR(A, 2, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 3, '==>' || SUBSTR(A, 3, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 4, '==>' || SUBSTR(A, 4, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 5, '==>' || SUBSTR(A, 5, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 6, '==>' || SUBSTR(A, 6, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 7, '==>' || SUBSTR(A, 7, 1) || '<==' FROM SESSION.A UNION ALL \
SELECT 8, '==>' || SUBSTR(A, 8, 1) || '<==' FROM SESSION.A ORDER BY 1

DROP TABLE SESSION.A

B.

Nov 12 '05 #2
Hmm... Just playing with WITH.

DECLARE GLOBAL TEMPORARY TABLE A (A CHAR(8))
INSERT INTO SESSION.A VALUES('5H 7B3d')

WITH B (B) AS (VALUES 1, 2, 3, 4, 5, 6, 7, 8) SELECT B, (SELECT '==>'
|| SUBSTR(A, B, 1) || '<==' FROM SESSION.A) FROM B

UPDATE SESSION.A SET A = '5H 7B3d'

WITH B (B) AS (VALUES 1, 2, 3, 4, 5, 6, 7, 8) SELECT B, (SELECT '==>'
|| SUBSTR(A, B, 1) || '<==' FROM SESSION.A) FROM B

DROP TABLE SESSION.A

Nov 12 '05 #3
Mesan wrote:
Here's the question:
How do you get DB2 to update a char(n) field with multiple spaces right
next to each other without having the additional spaces being omitted?

Here's the background:
We have a field "codes2" that's defined as char(8) that we use to keep
eight different codes (i.e. codes2[0] = something, codes2[1] =
something else, etc.). I'm sure that idea is nothing new to anyone but
our problem arises when we try to store two spaces (' ') right next to
each other.

This command:

EXEC SQL UPDATE TBLNAME SET CODES2 = '5H 7B3d' WHERE ...;

Completes without errors but when you look in the table to see what was
actually done, codes2 = '5H 7B3d', the DB2 just decided to omit one of
the spaces and slide the rest of the string over. You can imagine our
problem when we've got programs looking for the value in codes2[3] and
instead of finding a space (' ') it finds a 7...not good.

What's the language the SQL is embedded into?
This does have a taste of a client bug.
Also which codepage is used. There are umpteen versions of space in
Unicode...

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
The SQL is embedded into a C program running on OS/2 compiled with IBM
Visual Age C++ 3.0. If I remember right, the code page our OS/2
clients use to talk to our OS/2 server is 437, but I could be wrong
(although I'm almost positive). I could reproduce it through the
command line with manual insert commands. Very weird eh? I got the
problem fixed in the program by using a cursor (instead of a normal
"EXEC SQL ..." command) but still, it's a very odd problem.

Thanks for your reply,

Mesan

Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Sharman | last post by:
Writing a form, several questions have got a list of checkboxes, with associated descriptions (mostly one word), all on a line. Eg: Describe yourself: Fat Hairy Ugly Wears glasses. I want to...
4
by: epaetz | last post by:
I'm doing a bcp out of a table to a file. Some of the fields in a record may have an empty string. When I bcp out to the file and examine it, the fields that have an empty string in the database...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
12
by: Magix | last post by:
Hi, Everytime I received a fix-length of string, let say 15 (the unused portion will filled with Spaces before receive), I want to remove the Spaces from END until I encounter a non-space char....
8
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a...
4
by: irsmartt | last post by:
How can I allow a user (in a command prompt) to enter a string of characters and put spaces in it? I use Dev C++. Example: char google; cin>> google; Whenever I try this and output the...
15
by: DanielJohnson | last post by:
I am writing a program in which I am removing all the spaces from the string. I thought that I could do it two ways. One was parsing the string character by character and copying onto another...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
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
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...
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
jinu1996
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...
1
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.