473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2 Multi Value Parameter

Happy Thursday Everyone,

I am trying to create a parameter that is one long varchar but that
will be used in a SQL statement IN function:

//string queryString = GetCurrentTitle s();
//Below is for Test
string queryString = "45322,32222,33 344,55555";

dataset catalogDS = new dataset();

StringBuilder sb = new StringBuilder() ;
sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHER E TITLE_NO in(?) ");

IBM.Data.DB2.DB 2Command ProcedureComman d =
new IBM.Data.DB2.DB 2Command(sb.ToS tring(),
_DB2Connection) ;
ProcedureComman d.CommandType = System.Data.Com mandType.Text;

IBM.Data.DB2.DB 2Parameter parameter = new
IBM.Data.DB2.DB 2Parameter("TIT LE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Direc tion = System.Data.Par ameterDirection .Input;
parameter.Size = queryString.Len gth;
parameter.Value = queryString;
ProcedureComman d.Parameters.Ad d(parameter);

IBM.Data.DB2.DB 2DataReader dataReader =
ProcedureComman d.ExecuteReader ();
The problem is the string is passed in as a Varchar so DB2 puts single
quotes around it and the TITLE_NO field is an integer. I can do:
WHERE CAST(TITLE_NO as VARCHAR) in (?) but then it can't use the
index that was created for this field (over 6 million rows).

The results in queryString can be up to 500 title numbers coming back
so doing some kind of a static parameter query would be a nightmare
(too many ? literally :) ).

I am trying to get this to work as a paramaterized query instead of
passing in the string into a stored proc because this is a mainframe
environment and I don't want to do any cobol programming if i can help
it. (no offense to you Cobol programmers)

Any help on this is appreciated!

Trevis
Sep 4 '08 #1
5 5298
On Sep 4, 12:27*pm, Trevisc <trev...@gmail. comwrote:
Happy Thursday Everyone,

I am trying to create a parameter that is one long varchar but that
will be used in a SQL statement IN function:

//string queryString = GetCurrentTitle s();
//Below is for Test
string queryString = "45322,32222,33 344,55555";

dataset catalogDS = new dataset();

* * * * * * StringBuilder sb = new StringBuilder() ;
* * * * * * sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME, ");
* * * * * * sb.Append("FROM TITLES ");
* * * * * * sb.Append("WHER E TITLE_NO in(?) ");

IBM.Data.DB2.DB 2Command ProcedureComman d =
new IBM.Data.DB2.DB 2Command(sb.ToS tring(),
_DB2Connection) ;
ProcedureComman d.CommandType = System.Data.Com mandType.Text;

IBM.Data.DB2.DB 2Parameter parameter = new
IBM.Data.DB2.DB 2Parameter("TIT LE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Direc tion = System.Data.Par ameterDirection .Input;
parameter.Size = queryString.Len gth;
parameter.Value = queryString;
ProcedureComman d.Parameters.Ad d(parameter);

IBM.Data.DB2.DB 2DataReader dataReader =
ProcedureComman d.ExecuteReader ();

The problem is the string is passed in as a Varchar so DB2 puts single
quotes around it and the TITLE_NO field is an integer. *I can do:
WHERE CAST(TITLE_NO as VARCHAR) in (?) * but then it can't use the
index that was created for this field (over 6 million rows).

The results in queryString can be up to 500 title numbers coming back
so doing some kind of a static parameter query would be a nightmare
(too many ? literally :) ).

I am trying to get this to work as a paramaterized query instead of
passing in the string into a stored proc because this is a mainframe
environment and I don't want to do any cobol programming if i can help
it. *(no offense to you Cobol programmers)

Any help on this is appreciated!

Trevis
Isn't the following possible?
string queryString = "45322,32222,33 344,55555";
dataset catalogDS = new dataset();
StringBuilder sb = new StringBuilder() ;
sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHER E TITLE_NO in(" + queryString + ") ");
IBM.Data.DB2.DB 2Command ProcedureComman d =
new IBM.Data.DB2.DB 2Command(sb.ToS tring(),
_DB2Connection) ;
ProcedureComman d.CommandType = System.Data.Com mandType.Text;

/* don't need this anymore
IBM.Data.DB2.DB 2Parameter parameter = new
IBM.Data.DB2.DB 2Parameter("TIT LE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Direc tion = System.Data.Par ameterDirection .Input;
parameter.Size = queryString.Len gth;
parameter.Value = queryString;
ProcedureComman d.Parameters.Ad d(parameter);
*/
IBM.Data.DB2.DB 2DataReader dataReader =
ProcedureComman d.ExecuteReader ();
Sep 4 '08 #2
Trevisc wrote:
I am trying to create a parameter that is one long varchar but that
will be used in a SQL statement IN function:
string queryString = "45322,32222,33 344,55555";

dataset catalogDS = new dataset();

StringBuilder sb = new StringBuilder() ;
sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHER E TITLE_NO in(?) ");
IBM.Data.DB2.DB 2Parameter parameter = new
IBM.Data.DB2.DB 2Parameter("TIT LE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Direc tion = System.Data.Par ameterDirection .Input;
parameter.Size = queryString.Len gth;
parameter.Value = queryString;
ProcedureComman d.Parameters.Ad d(parameter);
The problem is the string is passed in as a Varchar so DB2 puts single
quotes around it and the TITLE_NO field is an integer. I can do:
WHERE CAST(TITLE_NO as VARCHAR) in (?) but then it can't use the
index that was created for this field (over 6 million rows).
I am trying to get this to work as a paramaterized query instead of
passing in the string into a stored proc
Parameters are intended to be 1 value.

I am not aware of any database/ADO.NET provider that can do what
you want.

Bad old dynamic SQL !

Using a SP doesn't solve the problem.

Arne
Sep 5 '08 #3
On Sep 4, 8:34*pm, Arne Vajhøj <a...@vajhoej.d kwrote:
Trevisc wrote:
I am trying to create a parameter that is one long varchar but that
will be used in a SQL statement IN function:
string queryString = "45322,32222,33 344,55555";
dataset catalogDS = new dataset();
* * * * * * StringBuilder sb = new StringBuilder() ;
* * * * * * sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME,");
* * * * * * sb.Append("FROM TITLES ");
* * * * * * sb.Append("WHER E TITLE_NO in(?) ");
IBM.Data.DB2.DB 2Parameter parameter = new
IBM.Data.DB2.DB 2Parameter("TIT LE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Direc tion = System.Data.Par ameterDirection .Input;
parameter.Size = queryString.Len gth;
parameter.Value = queryString;
ProcedureComman d.Parameters.Ad d(parameter);
The problem is the string is passed in as a Varchar so DB2 puts single
quotes around it and the TITLE_NO field is an integer. *I can do:
WHERE CAST(TITLE_NO as VARCHAR) in (?) * but then it can't use the
index that was created for this field (over 6 million rows).
I am trying to get this to work as a paramaterized query instead of
passing in the string into a stored proc

Parameters are intended to be 1 value.

I am not aware of any database/ADO.NET provider that can do what
you want.

Bad old dynamic SQL !

Using a SP doesn't solve the problem.

Arne- Hide quoted text -

- Show quoted text -
He could have a sproc, asuming DB2 implements the equivalent of EXEC,
available under MS SQL Server like this:
CREATE PROC
@param1 varchar(4000)
AS
DECLARE @SQL varchar(8000)
SET @SQL= 'SELECT
....
WHERE WHERE TITLE_NO in(' + @Param1 + ') '

EXEC @Param1

Not the optimal solution, as far as I know, but possible,
Sep 5 '08 #4
G.S. wrote:
On Sep 4, 8:34 pm, Arne Vajhøj <a...@vajhoej.d kwrote:
>Trevisc wrote:
>>I am trying to create a parameter that is one long varchar but that
will be used in a SQL statement IN function:
string queryString = "45322,32222,33 344,55555";
dataset catalogDS = new dataset();
StringBuilder sb = new StringBuilder() ;
sb.Append("SELE CT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHER E TITLE_NO in(?) ");
IBM.Data.DB2. DB2Parameter parameter = new
IBM.Data.DB2. DB2Parameter("T ITLE_NO", IBM.Data.DB2.DB 2Type.VarChar);
parameter.Dir ection = System.Data.Par ameterDirection .Input;
parameter.Siz e = queryString.Len gth;
parameter.Val ue = queryString;
ProcedureComm and.Parameters. Add(parameter);
The problem is the string is passed in as a Varchar so DB2 puts single
quotes around it and the TITLE_NO field is an integer. I can do:
WHERE CAST(TITLE_NO as VARCHAR) in (?) but then it can't use the
index that was created for this field (over 6 million rows).
I am trying to get this to work as a paramaterized query instead of
passing in the string into a stored proc
Parameters are intended to be 1 value.

I am not aware of any database/ADO.NET provider that can do what
you want.

Bad old dynamic SQL !

Using a SP doesn't solve the problem.

He could have a sproc, asuming DB2 implements the equivalent of EXEC,
available under MS SQL Server like this:
CREATE PROC
@param1 varchar(4000)
AS
DECLARE @SQL varchar(8000)
SET @SQL= 'SELECT
...
WHERE WHERE TITLE_NO in(' + @Param1 + ') '

EXEC @Param1

Not the optimal solution, as far as I know, but possible,
Yes.

But that is not the SP solving the problem - that is the dynamic SQL !

Arne
Sep 5 '08 #5
Loop through the values, add an additional clause to your SQL checking

title_no begins with param_1,
or
title_no contains ,param_1,
or
title_no ends with ,param_1

then you can loop through the values again with a normal FOR loop and set
the parameters to their values before executing.
Then you can fire the DB admin :-)

Pete

Sep 5 '08 #6

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

Similar topics

1
11797
by: Berend | last post by:
I am trying to pass multi values into a where clause with an in clause in a store procedure to use in a Crystal report. This can change depending on the user. Maybe there is another way to pass multi values. CREATE OR REPLACE PROCEDURE eva_sp_wrk014_spec_test ( p_eva_product_header_ids IN VARCHAR2, cur_spec_cd IN...
0
1713
by: VictorCorey | last post by:
Is it possible to use a multi-parameter query in .NET Here's the method Public Function SearchCatalog(ByVal searchString As String, ByVal allWords As String) As OleDbDataReade ' Create the connection objec Dim connection As New OleDbConnection(connectionString Dim command As New OleDbComman ' We guard agains bogus values here - if we...
10
125430
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use : set @pCode='A1','A2','A3' but get an error : Incorrect syntax near ','
11
4433
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
4
6368
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically allocated a set of pointer to pointers as my multi-dimensional arrays. Here is my code (i have omitted checking calloc's return value to make this...
1
1709
by: monadel | last post by:
Hi all, I am a beginner of SQL Server 2005. How do you display multi-values parameters with coma in the SQL Server 2005 reporting?. I believe we have to create a fucntion to do this, but how do you create a function in SQL Server 2005? we only can create / alter table. I have an example from a book but it doesnt help me at all. it just...
137
6585
by: mathieu.dutour | last post by:
Dear all, I want to do multiprecision floating point, i.e. I want to go beyond single precision, double precision and have quadruple precision, octuple precision and the like, and possibly with high speed. What would be the possible alternatives? Thanks for any help
0
2555
by: Mark C. Stock | last post by:
"Mark C. Stock" <mcstockX@Xenquery .comwrote in message news:... | | "Berend" <Berend.Brinkhuis@evatone.comwrote in message | news:bdd9ac20.0401271301.22cdb65e@posting.google.com... | | I am trying to pass multi values into a where clause with an in clause | | in a store procedure to use in a Crystal report. This can change | | depending on...
1
6777
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from...
0
7471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7740
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7985
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5387
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1962
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 we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.