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 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();
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
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,
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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 :...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |