473,498 Members | 1,639 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 = GetCurrentTitles();
//Below is for Test
string queryString = "45322,32222,33344,55555";

dataset catalogDS = new dataset();

StringBuilder sb = new StringBuilder();
sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHERE TITLE_NO in(?) ");

IBM.Data.DB2.DB2Command ProcedureCommand =
new IBM.Data.DB2.DB2Command(sb.ToString(),
_DB2Connection);
ProcedureCommand.CommandType = System.Data.CommandType.Text;

IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.Parameters.Add(parameter);

IBM.Data.DB2.DB2DataReader dataReader =
ProcedureCommand.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 5292
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 = GetCurrentTitles();
//Below is for Test
string queryString = "45322,32222,33344,55555";

dataset catalogDS = new dataset();

* * * * * * StringBuilder sb = new StringBuilder();
* * * * * * sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME, ");
* * * * * * sb.Append("FROM TITLES ");
* * * * * * sb.Append("WHERE TITLE_NO in(?) ");

IBM.Data.DB2.DB2Command ProcedureCommand =
new IBM.Data.DB2.DB2Command(sb.ToString(),
_DB2Connection);
ProcedureCommand.CommandType = System.Data.CommandType.Text;

IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.Parameters.Add(parameter);

IBM.Data.DB2.DB2DataReader dataReader =
ProcedureCommand.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,33344,55555";
dataset catalogDS = new dataset();
StringBuilder sb = new StringBuilder();
sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHERE TITLE_NO in(" + queryString + ") ");
IBM.Data.DB2.DB2Command ProcedureCommand =
new IBM.Data.DB2.DB2Command(sb.ToString(),
_DB2Connection);
ProcedureCommand.CommandType = System.Data.CommandType.Text;

/* don't need this anymore
IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.Parameters.Add(parameter);
*/
IBM.Data.DB2.DB2DataReader dataReader =
ProcedureCommand.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,33344,55555";

dataset catalogDS = new dataset();

StringBuilder sb = new StringBuilder();
sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHERE TITLE_NO in(?) ");
IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.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.

Arne
Sep 5 '08 #3
On Sep 4, 8:34*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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,33344,55555";
dataset catalogDS = new dataset();
* * * * * * StringBuilder sb = new StringBuilder();
* * * * * * sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME,");
* * * * * * sb.Append("FROM TITLES ");
* * * * * * sb.Append("WHERE TITLE_NO in(?) ");
IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.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.

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.dkwrote:
>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,33344,55555";
dataset catalogDS = new dataset();
StringBuilder sb = new StringBuilder();
sb.Append("SELECT TITLE_NO, SEQ_NO, TITLE_NAME, ");
sb.Append("FROM TITLES ");
sb.Append("WHERE TITLE_NO in(?) ");
IBM.Data.DB2.DB2Parameter parameter = new
IBM.Data.DB2.DB2Parameter("TITLE_NO", IBM.Data.DB2.DB2Type.VarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Size = queryString.Length;
parameter.Value = queryString;
ProcedureCommand.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
11795
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...
0
1700
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...
10
125420
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 :...
11
4429
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...
4
6358
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...
1
1705
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...
137
6563
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...
0
2545
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...
1
6763
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...
0
7002
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
7165
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
7379
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
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
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...

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.