Unix Technical Forum

Multiple queries in a single SQL string

This is a discussion on Multiple queries in a single SQL string within the DB2 forums, part of the Database Server Software category; --> I am passing the following three queries in a string in VS.NET C# class string sql = "SELECT A ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 04:37 PM
KS
 
Posts: n/a
Default Multiple queries in a single SQL string

I am passing the following three queries in a string in VS.NET C# class

string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
TABLEC;";
OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
connection object)
DataSet ds = new DataSet;
thisAdapter.Fill(ds);

If the second query fails, the third query doesn't get executed. If the
first one fails (sql +100) the second and third will never be executed.
But i would like the later occuring queries to execute even if the prior
ones have an SQL +100. How do i accomplish this ?

Thanks,
Karthik

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 04:37 PM
Knut Stolze
 
Posts: n/a
Default Re: Multiple queries in a single SQL string

KS <ks@nospam.net> wrote:

> I am passing the following three queries in a string in VS.NET C# class
>
> string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
> TABLEC;";
> OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
> connection object)
> DataSet ds = new DataSet;
> thisAdapter.Fill(ds);
>
> If the second query fails, the third query doesn't get executed. If the
> first one fails (sql +100) the second and third will never be executed.
> But i would like the later occuring queries to execute even if the prior
> ones have an SQL +100. How do i accomplish this ?


An easy way would be to get the various queries to the point where no +100
is produced in the first place. Then you would have to handle the
situation in your application. If you extend your queries like that, you
should get at least one row - always:

SELECT a
FROM tableA
UNION
SELECT x
FROM TABLE ( VALUES(0) ) AS t(x)
WHERE NOT EXISTS ( SELECT 1
FROM tableA );
<second query in a similar fashion>

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 04:37 PM
Serge Rielau
 
Posts: n/a
Default Re: Multiple queries in a single SQL string

+100 is not an error, it's a warning. Are you inded seeing that +100
fails the batch?
I recall dimply that there is some CLI parameter (cli.ini file?) that
meedles with how ODBC handles warnings.
You may want to check the CLI docs.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 04:37 PM
joerg
 
Posts: n/a
Default Re: Multiple queries in a single SQL string

Hello,
what do what to get as a result of these queries. It seems that you
want to build a UNION of these selects, so the select would look like

select A from tableA
union
select B from tableB
union
select C from tableC

as long as A,B and C are of the same datatype.

Joerg

KS <ks@nospam.net> wrote in message news:<cZoNb.16210$4l3.10950@nwrddc02.gnilink.net>. ..
> I am passing the following three queries in a string in VS.NET C# class
>
> string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
> TABLEC;";
> OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
> connection object)
> DataSet ds = new DataSet;
> thisAdapter.Fill(ds);
>
> If the second query fails, the third query doesn't get executed. If the
> first one fails (sql +100) the second and third will never be executed.
> But i would like the later occuring queries to execute even if the prior
> ones have an SQL +100. How do i accomplish this ?
>
> Thanks,
> Karthik

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:33 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com