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

Wildcards in DB2 SQL

Hi,

I am new to this forums and new to DB2 too.

I hav a query.
My table is

Name
ajay
shubhangi
kunal

when i am executing the query
select name from table_name where name like '%i'
answer coming is 0 record selected instead of shubhangi.

another query
select name from table_name where like 's%i'
again answer coming is 0 record.
according to me it should be shubhangi

can anyone tell me wats wrong with it or help me write a query dat start with s and end with i.
Any help is highly appreciated.

Thanks,
shubhangi
Nov 24 '10 #1
1 1576
vijay2082
112 100+
Hi,

Works perfectly for me as designed. Look at below set of steps to see what could be going wrong in your case.

C:\backup>db2 create table db2admin.mytable(name varchar(30))
DB20000I The SQL command completed successfully.

C:\backup>db2 "insert into db2admin.mytable values('ajay')
DB20000I The SQL command completed successfully.

C:\backup>db2 "insert into db2admin.mytable values('shubhangi')"
DB20000I The SQL command completed successfully.

C:\backup>db2 "insert into db2admin.mytable values('kunal')"
DB20000I The SQL command completed successfully.

C:\backup>db2 commit
DB20000I The SQL command completed successfully.

C:\backup>db2 select * from db2admin.mytable

NAME
------------------------------
ajay
shubhangi
kunal

3 record(s) selected.


C:\backup>db2 "select name from db2admin.mytable where name like '%i'"

NAME
------------------------------
shubhangi

1 record(s) selected.

C:\backup>db2 "select name from db2admin.mytable where name like 's%i'"

NAME
------------------------------
shubhangi

1 record(s) selected.

> Let us try inserting a name in upper case as below and see what happens to next query.

C:\backup>db2 "insert into db2admin.mytable values('SHUBHANGI')"
DB20000I The SQL command completed successfully.

C:\backup>db2 select * from db2admin.mytable

NAME
------------------------------
ajay
shubhangi
kunal
SHUBHANGI

4 record(s) selected.


> Below query still returns the odl result as expected
C:\backup>db2 "select name from db2admin.mytable where name like 's%i'"

NAME
------------------------------
shubhangi

1 record(s) selected.


> Below query returns both entry when we do a case insensitive search

C:\backup>db2 "select name from db2admin.mytable where lower(name) like 's%i'"

NAME
------------------------------
shubhangi
SHUBHANGI

2 record(s) selected.


Cheers, Vijay
Nov 25 '10 #2

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

Similar topics

6
by: Bharath Dhurjati | last post by:
Hello, I am looking for documentation that specifies the following behavior exhibited by java. The following (assuming MyClass.class is accessible and has a main()) java MyClass * yields...
1
by: Ralph Noble | last post by:
I thought this problem would go away over the Christmas holiday, but of course it did not. I'm trying to write a stored procedure incorporating wildcards, so I can search for variations. Example,...
3
by: sashi | last post by:
Hi, Is it possible to use wildards in SQL to drop a constraint on a table? Thanks!
11
by: Shyguy | last post by:
I need to import a text file pretty much daily. I download the file and change the name to a standard name and then run the code to import the file into a table in my database. The problem is...
10
by: Alvaro Puente | last post by:
Hi all! Do any of you know if wildcards are accepted when calling rename() function? Thanks/Alvaro
6
by: Andy | last post by:
I have a form with several ComboBoxes. One of these is Surname, can I make it select all the Smiths for example by using wildcards? At the moment my query only picks up the individual Surname...
2
by: Dennis | last post by:
I am trying to implement a "Find and Replace" dialog that allows using wildcards in the find string, much like the Find and Replace Dialogs in Ms Word, etc. Are there any references or examples on...
1
by: Anandan | last post by:
Hi, This is regarding Dataset Filter: WILDCARD CHARACTERS Both the * and % can be used interchangeably for wildcards in a LIKE comparison. If the string in a LIKE clause contains a * or %,...
19
by: Alan Carpenter | last post by:
Access 8 on Win98 and WinXP I'm having trouble with wildcards in the .Filename property of the FileSearch Object giving different results on win98 and XP. I've been successfully using...
5
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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?
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...

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.