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

Select Range Query

Hi all,

This is probably a simple problem for most of you.. Let me know if you
have any pointers for me. I am new to DB2.

In my stored procedure I want to select records that match a range of
values.

================================================== =======

create PROCEDURE DB2. sp_gettotry_logs (
IN myid
CHARACTER(36)
)
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE c1 CURSOR WITH RETURN FOR
select * from db2.playlogs_ where playerid_ in
( myid ) ;
OPEN c1;
END

================================================== =========

How do I call this procedure and pass a range of values ?

I've tried:
call db2.sp_gettotry_logs( '19','01')

This doesn't work because the function is expecting only one parameter
.... but I want to get record results where playerid is either '19' or
'01'.

Thanks in advance.

-Anil

Feb 10 '06 #1
3 4012
an******@gmail.com wrote:
Hi all,

This is probably a simple problem for most of you.. Let me know if you
have any pointers for me. I am new to DB2.

In my stored procedure I want to select records that match a range of
values.

================================================== =======

create PROCEDURE DB2. sp_gettotry_logs (
IN myid
CHARACTER(36)
)
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE c1 CURSOR WITH RETURN FOR
select * from db2.playlogs_ where playerid_ in
( myid ) ;
OPEN c1;
END

================================================== =========

How do I call this procedure and pass a range of values ?

I've tried:
call db2.sp_gettotry_logs( '19','01')

This doesn't work because the function is expecting only one parameter
... but I want to get record results where playerid is either '19' or
'01'.

Thanks in advance.

-Anil

CREATE PROCEDURE DB2. sp_gettotry_logs (
IN myid CHARACTER(36)
)
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE txt VARCHAR(1000);
DECLARE stmt STATEMENT;
DECLARE c1 CURSOR WITH RETURN FOR stmt;
SET txt = 'select * from db2.playlogs_ where playerid_ in ('
|| myid || ')';
PREPARE stmt FROM txt;
OPEN c1;
END

CALL DB2.sp_gettotry_logs('19,01');

I assume that playerid_ is a numeric, if it's a string you need to
escape the quotes when passing a constant:
CALL DB2.sp_gettotry_logs('''19'',''01''');

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Feb 10 '06 #2
> CREATE PROCEDURE DB2. sp_gettotry_logs (
IN myid CHARACTER(36)
) (SNIP)
CALL DB2.sp_gettotry_logs('19,01');


Because, data type of string constant('19,01') is VARCHAR,
Perhaps, you need to change data type of argument like this:

CALL DB2.sp_gettotry_logs(CHAR('19,01'))

So, it's better to define input parameter as VARCHAR.

CREATE PROCEDURE DB2. sp_gettotry_logs (
IN myid VARCHAR(36)

Feb 10 '06 #3
Worked.. thanks :)

-Anil

Feb 10 '06 #4

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

Similar topics

5
by: Got2Go | last post by:
Hello Group, I have a table that has 3 columns: ID (int), datetime, Value(varchar) ID = ID for the SNMP device datetime = time record was added value = value added for that device. This...
4
by: psql-mail | last post by:
I am running a SELECT to get all tuples within a given date range. This query is much slwoer than i expected - am i missing something? I have a table 'meta' with a column 'in_date' of type...
3
by: Ker | last post by:
I have a query that works great. It gives me the min for multiple fields. Within this query, I also need to get the max of some fields too. I currently have output of Date Name ...
1
by: anilcool | last post by:
Hi all, This is probably a simple problem for most of you.. Let me know if you have any pointers for me. I am new to DB2. In my stored procedure I want to select records that match a range of...
1
by: suslikovich | last post by:
Hi all, I am getting this error when insert values from one table to another in the first table the values are varchar (10). In the second they are datetime. The format of the data is mm/dd/yyyy...
4
by: bizt | last post by:
Hi, I want to find an easy way to select only rows within a certain range when I do a select. Im sure I have seen this done with a SELECT statement but cant remember if or how it was done. Can...
2
Spazasaurus
by: Spazasaurus | last post by:
I am having trouble. I am not sure if it is not possible or not, but don't know any alternatives. I am converting my site from PHP and MYSQL to ASP.NET and MSSQL. In my current site. I did a query...
6
by: plaster1 | last post by:
Been trying to come up with a query to filter-down my sample set into distinct records. For instance, lets say column1 is a sample set, column2 is the parameter, and column3 is a name and column4...
2
by: shannonwhitty | last post by:
I am able to extract dates in the correct format i.e. SELECT CONVERT(VARCHAR(8), GETDATE(), 3) =dd/mm/yy My issue is that my users are selecting a date in this format and I need to select...
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...
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
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
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...

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.