Results 1 to 10 of 10
Thread: sqljdbc driver UNION querys
- 02-18-2011, 12:13 PM #1
Member
- Join Date
- Feb 2011
- Location
- Spain
- Posts
- 26
- Rep Power
- 0
sqljdbc driver UNION querys
Hi all,
i am having a problem with the sqljdbc driver related with Union querys.
My sql query is in the form QUERY1 Union QUERY2 Union Query3.
At the sqlServerManager i can get the data of the 3 querys, but at my application i only get data of the first query.
Can anyone tell me if this is related with my driver?
thanks in advance
- 02-18-2011, 02:13 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Doubt it.
The driver simply passes the SQL to the database.
If you showed us your code we might be able to point out the problem.
- 02-18-2011, 02:44 PM #3
Member
- Join Date
- Feb 2011
- Location
- Spain
- Posts
- 26
- Rep Power
- 0
ok, this is my code:
Java Code:Statement statment = con.createStatement(); ResultSet resVentasCadenas = statment .executeQuery(Querys.queryVentasTotal); .......... .......... while (resVentasCadenas.next()) { .................... }
- 02-18-2011, 03:57 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Which says nothing about your query.
What is the SQL?
- 02-24-2011, 08:42 AM #5
Member
- Join Date
- Feb 2011
- Location
- Spain
- Posts
- 26
- Rep Power
- 0
Sorry about the delay,
the sql query sintax is as folllows and it is working in the sqlservermanager:
Java Code:select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'TTTT', p.pais, p.nombre from XXXXXX v, XXXXXX t, XXXXXX paises p where v.tienda = t.tienda and t.pais = p.pais and v.fecha = CONVERT(DATETIME, '02/14/2011') and t.cerrada = 0 and t.cadena = 1 and v.seccion in (1,2) group by t.cadena, p.pais, p.nombre ,v.seccion -- ventas mismas tiendas UNION ALL select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'MMTT', p.pais, p.nombre from XXXXXX v, XXXXXX t, XXXXXX paises p where v.tienda = t.tienda and t.pais = p.pais and t.cadena = 1 and v.seccion in (1,2) and v.fecha = CONVERT(DATETIME, '02/14/2011') and 0 < (select count (*) from XXXXX v2 where v2.tienda = v.tienda and v2.fecha = CONVERT(DATETIME, '02/15/2010') and t.cerrada = 0 ) group by t.cadena, p.pais, p.nombre, v.seccion UNION ALL select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'MMTT_A1' , p.pais, p.nombre from XXXXXX v, XXXXXX t, XXXXXX paises p where v.tienda = t.tienda and t.pais = p.pais and v.fecha = CONVERT(DATETIME, '02/15/2010') and t.cerrada = 0 and t.cadena = 1 and v.seccion in (1,2) group by t.cadena, p.pais, p.nombre, v.seccion order by t.cadena, p.pais
- 02-24-2011, 08:50 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Then you should get all of the information (in a single resultset of course). If you can prove that you do not, then create a small, self-contained, compilable, executable program and the explicit data to go with it, that demonstrates the problem and submit that as a bug to the vendor from which you got the JDBC driver.
- 02-24-2011, 09:22 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Don't stick comments in your SQL unless you can guarantee that they will appear on a single line by themselves.Java Code:-- ventas mismas tiendas
Since I suspect you are concatenating that String together then the above comment is actually commenting out all the remaining bit of the SQL, since it's all on one line as far as the database is concerned.
ETA: And in case anyone is wondering, yes I have done this. In Hibernate, on a large stored query that I wanted to try and document. Funnily enough the query didn't work since 90% of it was actually commented out.
- 02-24-2011, 12:19 PM #8
Member
- Join Date
- Feb 2011
- Location
- Spain
- Posts
- 26
- Rep Power
- 0
Ok, thank you Tolls, i have changed what you said about comments.
Now my sql code is as follows, but now i am only getting data of the 3 sql union query. I have no results about the 2 first querys.
żwhat's happening now?
Java Code:select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'TTTT', p.pais, p.nombre " + " from XXXX v, TTTTT t, PPPPPP p " + " where v.tienda = t.tienda " + " and t.pais = p.pais " + " and v.fecha = CONVERT(DATETIME, ?) " + " and t.cerrada = 0 and t.cadena = ? and v.seccion in (1,2) and p.pais = ? " + " group by t.cadena, p.pais, p.nombre ,v.seccion " + " UNION ALL" + " select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'MMTT', p.pais, p.nombre " + " from VVVVVVV v, TTTTTTTT t, PPPPPPP p " + " where v.tienda = t.tienda " + " and t.pais = p.pais and t.cadena = ? and v.seccion in (1,2) and p.pais = ? " + " and v.fecha = CONVERT(DATETIME, ?) " + " and 0 < (select count (*) " + " from VVVV v2 " + " where v2.tienda = v.tienda " + " and v2.fecha = CONVERT(DATETIME, ?)" + " and t.cerrada = 0 )" + " group by t.cadena, p.pais, p.nombre, v.seccion" + " UNION ALL" + " select sum(v.importeConIva * p.cambioreferencia) as importeTicket, t.cadena, v.seccion, 'MMTT_A1' , p.pais, p.nombre " + " from VVVVVVV v, TTTTTTTT t, PPPPPPPP p " + " where v.tienda = t.tienda " + " and t.pais = p.pais " + " and v.fecha = CONVERT(DATETIME, ?) " + " and t.cerrada = 0 and t.cadena = ? and v.seccion in (1,2) and p.pais = ? " + " group by t.cadena, p.pais, p.nombre, v.seccion
- 02-24-2011, 12:28 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
You've lost me there.
There are 3 parts to your query, which are UNIONed together.
You say you are getting data from these, so what are you having a problem with?
- 02-24-2011, 12:37 PM #10
Member
- Join Date
- Feb 2011
- Location
- Spain
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
JDBC Driver
By Ursula in forum New To JavaReplies: 6Last Post: 08-23-2010, 05:41 PM -
help for sqljdbc
By cemo in forum Advanced JavaReplies: 1Last Post: 05-12-2010, 03:21 AM -
union in linked list
By IT student in forum New To JavaReplies: 4Last Post: 01-02-2010, 11:34 AM -
Driver for Java-SQL
By Pr0n in forum New To JavaReplies: 7Last Post: 07-23-2009, 11:30 PM -
Printing the union and instersection of two sets
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks