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')
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] "Willo" <willoberto@yahoo.com.mx> wrote in message news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl...
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')
Sorry, im newie, what is BOL? [quoted text, click to view] "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message news:ewTw6ZucHHA.5052@TK2MSFTNGP05.phx.gbl... > Check out SELECT TOP in the BOL. > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > . > "Willo" <willoberto@yahoo.com.mx> wrote in message > news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl... > 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') > >
BOL = Boos Online -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada .. [quoted text, click to view] "Willo" <willoberto@yahoo.com.mx> wrote in message news:eE5kvnvcHHA.4032@TK2MSFTNGP02.phx.gbl...
Sorry, im newie, what is BOL? [quoted text, click to view] "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message news:ewTw6ZucHHA.5052@TK2MSFTNGP05.phx.gbl... > Check out SELECT TOP in the BOL. > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > . > "Willo" <willoberto@yahoo.com.mx> wrote in message > news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl... > 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') > >
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] "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message news:%23g4xCsvcHHA.4172@TK2MSFTNGP05.phx.gbl... > BOL = Boos Online > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > . > "Willo" <willoberto@yahoo.com.mx> wrote in message > news:eE5kvnvcHHA.4032@TK2MSFTNGP02.phx.gbl... > Sorry, im newie, what is BOL? > > > "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message > news:ewTw6ZucHHA.5052@TK2MSFTNGP05.phx.gbl... >> Check out SELECT TOP in the BOL. >> >> -- >> Tom >> >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON Canada >> . >> "Willo" <willoberto@yahoo.com.mx> wrote in message >> news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl... >> 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') >> >> > >
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] "Roger Wolter[MSFT]" <rwolter@online.microsoft.com> wrote in message news:EFECC691-7184-4EF7-A78F-B01E42B89F32@microsoft.com...
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] "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message news:%23g4xCsvcHHA.4172@TK2MSFTNGP05.phx.gbl... > BOL = Boos Online > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > . > "Willo" <willoberto@yahoo.com.mx> wrote in message > news:eE5kvnvcHHA.4032@TK2MSFTNGP02.phx.gbl... > Sorry, im newie, what is BOL? > > > "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message > news:ewTw6ZucHHA.5052@TK2MSFTNGP05.phx.gbl... >> Check out SELECT TOP in the BOL. >> >> -- >> Tom >> >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON Canada >> . >> "Willo" <willoberto@yahoo.com.mx> wrote in message >> news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl... >> 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') >> >> > >
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] "Roger Wolter[MSFT]" <rwolter@online.microsoft.com> wrote in message news:EFECC691-7184-4EF7-A78F-B01E42B89F32@microsoft.com... > 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 > > "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message > news:%23g4xCsvcHHA.4172@TK2MSFTNGP05.phx.gbl... > > BOL = Boos Online > > > > -- > > Tom > > > > ---------------------------------------------------- > > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > > SQL Server MVP > > Toronto, ON Canada > > . > > "Willo" <willoberto@yahoo.com.mx> wrote in message > > news:eE5kvnvcHHA.4032@TK2MSFTNGP02.phx.gbl... > > Sorry, im newie, what is BOL? > > > > > > "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message > > news:ewTw6ZucHHA.5052@TK2MSFTNGP05.phx.gbl... > >> Check out SELECT TOP in the BOL. > >> > >> -- > >> Tom > >> > >> ---------------------------------------------------- > >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > >> SQL Server MVP > >> Toronto, ON Canada > >> . > >> "Willo" <willoberto@yahoo.com.mx> wrote in message > >> news:etlH8OucHHA.284@TK2MSFTNGP05.phx.gbl... > >> 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') > >> > >> > > > > >
Don't see what you're looking for? Try a search.
|