• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple "select" in one query

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
Im connecting to a MS SQL database 7.0 using JDBC. I have to make the same query multiple times with the only change being a new "where" clause. Im trying to do this with a query that looks like this:
queryString= "select sum(ITEM) as item from database where condition1; select sum(ITEM) as item2 from database where condition2;";
and Im getting the result of the query out in to integers like this:
itemInt = rs.getInt(item);
item2Int = rs.getInt(item2);
This works fine if I only have 1 "select" query in the queryString, but when I put in the second "select" query I get an SQLException that: Column "item2" not found.
Do I have to make seperate queryStrings for each timeperiod or can it be done in one??
If you need to see the code just ask.
Regards
S�ren Augustesen
[This message has been edited by S�ren Augustesen (edited December 15, 2001).]
[This message has been edited by S�ren Augustesen (edited December 15, 2001).]
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to make separate query strings. There is a way to do multiples - you can write a stored procedure that will do the multiple SQL statements and use CallableStatement. But it looks like here you want 2 query strings.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim
Thanks for the quick answer, I'll give it a try.
Regards
S�ren Augustesen
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should try combination with union of selects.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic