473,383 Members | 1,717 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,383 software developers and data experts.

How to select the data which have space end of string one or more

Env: DB2 V8 + FP13

Question: How to select the data which have space end of string one or
more, like 'AB ','AB '

Case:
..Create Test Table
db2 "create table test (vname varchar(100)) "

..Insert Test Data
db2 "insert into test values('AB'), ('AB '),('AB '),('AB ')"

..Select only have one space end of string 'AB' with follow sql, but
result not match our expectation
db2 "select * from test where vname='AB '"
VNAME
-----
AB
AB
AB
AB

now, our solution use follow sql
db2 "select * from test where length(vname)=3 and VNAME='AB '"

But, Anyone know another alternate way can select string like 'AB ' ?
Thanks

Apr 20 '07 #1
7 7177
wu*******@gmail.com wrote:
Env: DB2 V8 + FP13

Question: How to select the data which have space end of string one or
more, like 'AB ','AB '

Case:
.Create Test Table
db2 "create table test (vname varchar(100)) "

.Insert Test Data
db2 "insert into test values('AB'), ('AB '),('AB '),('AB ')"

.Select only have one space end of string 'AB' with follow sql, but
result not match our expectation
db2 "select * from test where vname='AB '"
VNAME
-----
AB
AB
AB
AB

now, our solution use follow sql
db2 "select * from test where length(vname)=3 and VNAME='AB '"

But, Anyone know another alternate way can select string like 'AB ' ?
Try VNAME LIKE 'AB %'
No promises, but I think LIKE is special

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 20 '07 #2
On Apr 21, 1:29 am, Serge Rielau <srie...@ca.ibm.comwrote:
wugon....@gmail.com wrote:
Env: DB2 V8 + FP13
Question: How to select the data which have space end of string one or
more, like 'AB ','AB '
Case:
.Create Test Table
db2 "create table test (vname varchar(100)) "
.Insert Test Data
db2 "insert into test values('AB'), ('AB '),('AB '),('AB ')"
.Select only have one space end of string 'AB' with follow sql, but
result not match our expectation
db2 "select * from test where vname='AB '"
VNAME
-----
AB
AB
AB
AB
now, our solution use follow sql
db2 "select * from test where length(vname)=3 and VNAME='AB '"
But, Anyone know another alternate way can select string like 'AB ' ?

Try VNAME LIKE 'AB %'
No promises, but I think LIKE is special

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab- Hide quoted text -

- Show quoted text -
Hi Serge ,
Thanks your kindly advice, the LIKE syntax is work for our sql, Thanks

Apr 20 '07 #3
VNAME LIKE 'AB %'
This will match with the value of VNAME (for example) 'AB CD'.
If your data doesn't include such value, Serge's answer will be
enough.

But, if your data include such value, my idea is
SELECT *
FROM test
WHERE vname = 'AB'
AND LENGTH(vname) 2;

More:
If consider more general case to find the values which doesn't care
leading characters and there are one or more trailing blanks.
For example:
select 'AB ', 'AB ', 'AB ', 'AB C ', 'KLM ', 'KLM ', 'VWX YZ ',
'VWX YZ ' from follwing data.

INSERT INTO test
VALUES 'AB', 'AB ', 'AB ', 'AB ', 'AB C', 'AB C ', 'AB CD'
, 'KLM', 'KLM ', 'KLM ', 'VWX YZ', 'VWX YZ ', 'VWX YZ ';

Try
SELECT *
FROM test
WHERE LENGTH(RTRIM(vname)) < LENGTH(vname);

Apr 21 '07 #4
Tonkuma wrote:
>VNAME LIKE 'AB %'
This will match with the value of VNAME (for example) 'AB CD'.
If your data doesn't include such value, Serge's answer will be
enough.
Oh dear. That's why they must call it a head-cold.
I shouldn't post when I'm sick ;-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 21 '07 #5
Ray
On Apr 21, 6:23 pm, Serge Rielau <srie...@ca.ibm.comwrote:
Tonkuma wrote:
VNAME LIKE 'AB %'
This will match with the value of VNAME (for example) 'AB CD'.
If your data doesn't include such value, Serge's answer will be
enough.

Oh dear. That's why they must call it a head-cold.
I shouldn't post when I'm sick ;-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
So how much longer will it be until regular expressions come to
SQL? :D

Apr 23 '07 #6
Ian
Ray wrote:
>
So how much longer will it be until regular expressions come to
SQL? :D
You mean like:

http://www-128.ibm.com/developerwork...301stolze.html
Apr 23 '07 #7
Ian wrote:
Ray wrote:
>>
So how much longer will it be until regular expressions come to
SQL? :D

You mean like:

http://www-128.ibm.com/developerwork...301stolze.html
I also have a regexp article half finished based on ICU.
Looking for a partner in crime to drive it to the finish line.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 23 '07 #8

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

Similar topics

3
by: William Gill | last post by:
I can't help but think I'm re-inventing the wheel if I have to code my own interface! Isn't there some script, php code, or something (modifiable / customizable) available that lets me select...
5
by: shivaprasad | last post by:
Hi all, I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this.. ex: byte bytes = new byte; this bytes get filled up. Now I need to convert to string.
3
by: Peter Afonin | last post by:
Hello, I've never been dealing with the security before. Could you please help me to write a code to generate an MD5 data from a string? I've been using this example from MSDN: Function...
3
by: Tim Groulx | last post by:
Hello, I need to be able to select only the numeric data from a string that is in the form of iFuturePriceID=N'4194582' I have the following code working to remove all the non-numeric text...
0
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this tyext data into a string. I've got it working just fine, but I have to put the text data into into a...
4
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this text data into a string. I've got it working just fine, but I have to put the text data into into a...
4
by: Rainer Queck | last post by:
Hi NG, in my application a <myDataTable>.Select fails with "Syntax error in the expression." It took me a while, isolate the cause to this: To select some datarows from a data table I am...
3
by: amija0311 | last post by:
Hi, I am new using DB2 9.1 database by windows base. I want to query the data that contain string then translate the string into integer using DB2. The problems is If the data is null, i got the...
5
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a DataSet with 2 tables. Now I want to select data like a INNER JOIN from these tables. In SQL Syntax I would write: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.f1 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.