473,406 Members | 2,208 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,406 software developers and data experts.

Syntax issue: URGENT

Hello,

I have a requirement where I need to return all the ids from Table1 if
the column 'name' of Table1 is in (i.e. a substring of) the 'longname'
column of Table2. How do I correct my SQL query as the below one is
showing error:

select Table1.id from Table1, Table2 where (Table2.longname LIKE
'%'||Table1.name||'%')

Thanks in advance,
DW

Aug 1 '06 #1
6 1439
Hello.

select Table1.id
from Table1, Table2
where posstr(Table2.longname, Table1.name)!=0;

Hello,

I have a requirement where I need to return all the ids from Table1 if
the column 'name' of Table1 is in (i.e. a substring of) the 'longname'
column of Table2. How do I correct my SQL query as the below one is
showing error:

select Table1.id from Table1, Table2 where (Table2.longname LIKE
'%'||Table1.name||'%')

Thanks in advance,
DW
Aug 1 '06 #2
de*********@yahoo.com wrote:
Hello,

I have a requirement where I need to return all the ids from Table1 if
the column 'name' of Table1 is in (i.e. a substring of) the 'longname'
column of Table2. How do I correct my SQL query as the below one is
showing error:

select Table1.id from Table1, Table2 where (Table2.longname LIKE
'%'||Table1.name||'%')
There is no pretty way to do this.
The migration toolkit provides a Java function with a generalized LIKE.
You can also get nasty:
CREATE PROCEDURE INSTR_P(IN string VARCHAR(128),
IN substring VARCHAR(128),
OUT found CHAR(1))
DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION
SET found = CASE WHEN string LIKE '%' || substring || '%'
THEN 1 ELSE 0 END;

--#SET TERMINATOR @
CREATE FUNCTION INSTR(string VARCHAR(128),
substring VARCHAR (128))
RETURNS CHAR(1)
DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE result CHAR(1);
CALL INSTR_P(string, substring, result);
RETURN result;
END
@
--#SET TERMINATOR ;
SELECT
Table1.id from Table1, Table2
where INSTR(Table2.longname, Table1.name) = 1

I didn't test it...

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 1 '06 #3
de*********@yahoo.com wrote:
Hello,

I have a requirement where I need to return all the ids from Table1 if
the column 'name' of Table1 is in (i.e. a substring of) the 'longname'
column of Table2. How do I correct my SQL query as the below one is
showing error:

select Table1.id from Table1, Table2 where (Table2.longname LIKE
'%'||Table1.name||'%')
LIKE requires a constant string (either explicitly specified or originating
from a host variable) as pattern. This is not the case here because your
pattern in dynamic.

You can use the functions POSSTR or LOCATE for the test. Serge offered
another solution. Yet another approach is to use regular expression
matching as is described here:
http://www.ibm.com/developerworks/db...301stolze.html

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Aug 1 '06 #4
select Table1.id
from Table1, Table2
where posstr(Table2.longname, Table1.name)!=0;
I think POSSTR also have similar restriction for search string as LIKE.
So, you should use LOCATE.

select Table1.id
from Table1, Table2
where LOCATE(Table1.name, Table2.longname) 0;

Aug 1 '06 #5
Yes, that's true.
I tested this at my iSeries V5R3.
posstr in iSeries supports string expression (including column names)
in 2-nd argument...

select Table1.id
from Table1, Table2
where posstr(Table2.longname, Table1.name)!=0;
I think POSSTR also have similar restriction for search string as LIKE.
So, you should use LOCATE.

select Table1.id
from Table1, Table2
where LOCATE(Table1.name, Table2.longname) 0;
Aug 2 '06 #6
Dear All:
Thanks for all the responses.
DW

Aug 2 '06 #7

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

Similar topics

1
by: Amit D.Shinde | last post by:
Hi Experts, i am writting a stored procedure in sql server 7. Its a simple stored procedure It is my first stored procedure. I want insert a record in table if the primary key field user id...
7
by: | last post by:
I'm writing an ASP.NET app, using Visual Studio 2003. VS is running locally on my laptop, but the web app is running on a remote server. My laptop is not in the domain. I do have a domain account....
2
by: Bern McCarty | last post by:
In the old MEC++ syntax I can do this: // compile in VS 2005 shell with cl -clr:oldsyntax -LD ArrayCopyOldSyntax.cpp #using <mscorlib.dll> public __gc class CopyTest { private:...
2
by: Chris Walls | last post by:
We have created two (2) global resource files in App_GlobalResouces: Global.resx Global.es-MX.resx In an ASP.NET page, we use two different syntaxes to set text on the page, depending upon the...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
2
by: simplebelle | last post by:
hei can you give me what syntax i need to use to this problem, number converted in words (1 to 999,999),it should be contain in the menu example:the user type 11 the output should be eleven ...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
2
by: | last post by:
Hi all, I have an asp.net 2.0 website that accesses a locally hosted web service. This works fine on servers that are connected to our network. However, I am having a problem with a laptop...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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,...

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.