all groups > sql server new users > march 2007 >
You're in the

sql server new users

group:

different order in a union all clause


different order in a union all clause Willo
3/30/2007 9:54:35 AM
sql server new users: Hi:

i have this query, and i need to specify an order for each SELECT... is
there a way to do it?

Note:
On MySQL, all i need to do is to use parentheses to enclose each select...
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);--------------
Select c.Nombrecuenta,c.Codigotipocuenta,t.Nombretipocuenta,c.cta,

(s.SaldoInicial+(CASE when c.Naturaleza='D' then
((s.c01+s.c02)-(s.a01+s.a02))

else ((s.a01+s.a02)-(s.c01+s.c02)) end)) as Saldo

from admvdpv.dbo.cnt_saldos s

inner join Grupovilla.dbo.CuentasContables c on
s.id_cuentascontables=c.id_cuentascontables

inner join Grupovilla.dbo.TiposdeCuenta t on
c.codigotipocuenta=t.codigotipocuenta

where c.nivel = 1 and (LEFT(c.codigotipocuenta,1)='P')

union all

Select c.Nombrecuenta,c.Codigotipocuenta,t.Nombretipocuenta,c.cta,

(s.SaldoInicial+(CASE when c.Naturaleza='D' then
((s.c01+s.c02)-(s.a01+s.a02))

else ((s.a01+s.a02)-(s.c01+s.c02)) end)) as Saldo

from admvdpv.dbo.cnt_saldos s

inner join Grupovilla.dbo.CuentasContables c on
s.id_cuentascontables=c.id_cuentascontables

inner join Grupovilla.dbo.TiposdeCuenta t on
c.codigotipocuenta=t.codigotipocuenta

where c.nivel = 1 and (LEFT(c.codigotipocuenta,1)='C')

Re: different order in a union all clause Tom Moreau
3/30/2007 12:13:40 PM
Check out SELECT TOP in the BOL.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
[quoted text, click to view]
Hi:

i have this query, and i need to specify an order for each SELECT... is
there a way to do it?

Note:
On MySQL, all i need to do is to use parentheses to enclose each select...
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);--------------
Select c.Nombrecuenta,c.Codigotipocuenta,t.Nombretipocuenta,c.cta,

(s.SaldoInicial+(CASE when c.Naturaleza='D' then
((s.c01+s.c02)-(s.a01+s.a02))

else ((s.a01+s.a02)-(s.c01+s.c02)) end)) as Saldo

from admvdpv.dbo.cnt_saldos s

inner join Grupovilla.dbo.CuentasContables c on
s.id_cuentascontables=c.id_cuentascontables

inner join Grupovilla.dbo.TiposdeCuenta t on
c.codigotipocuenta=t.codigotipocuenta

where c.nivel = 1 and (LEFT(c.codigotipocuenta,1)='P')

union all

Select c.Nombrecuenta,c.Codigotipocuenta,t.Nombretipocuenta,c.cta,

(s.SaldoInicial+(CASE when c.Naturaleza='D' then
((s.c01+s.c02)-(s.a01+s.a02))

else ((s.a01+s.a02)-(s.c01+s.c02)) end)) as Saldo

from admvdpv.dbo.cnt_saldos s

inner join Grupovilla.dbo.CuentasContables c on
s.id_cuentascontables=c.id_cuentascontables

inner join Grupovilla.dbo.TiposdeCuenta t on
c.codigotipocuenta=t.codigotipocuenta

where c.nivel = 1 and (LEFT(c.codigotipocuenta,1)='C')

Re: different order in a union all clause Willo
3/30/2007 12:33:14 PM
Sorry, im newie, what is BOL?


[quoted text, click to view]

Re: different order in a union all clause Tom Moreau
3/30/2007 2:40:41 PM
BOL = Boos Online

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
[quoted text, click to view]
Sorry, im newie, what is BOL?


[quoted text, click to view]

Re: different order in a union all clause Roger Wolter[MSFT]
3/30/2007 4:33:42 PM
I thought it was Books Online but I like your definition better - but isn't
that spelled Booze Online?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

[quoted text, click to view]
Re: different order in a union all clause Tom Moreau
3/30/2007 7:45:43 PM
Dang! Looks like I need some Booze - Online or otherwise! ;-)

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
[quoted text, click to view]
I thought it was Books Online but I like your definition better - but isn't
that spelled Booze Online?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

[quoted text, click to view]
Re: different order in a union all clause Steve Dassin
4/1/2007 12:49:12 AM
You may see access paths clearly but apparently you are blind
as a bat when it comes to a Freudian slip. The best and brightest
{BSc, PhD, MCSE, MCDBA, MCITP, MCTS} always have
something interesting to say -:)


[quoted text, click to view]

AddThis Social Bookmark Button