Saturday, February 25, 2012

Multiple select statements in one query?

How can I run a select statement on data from a previous select statement
within the same query? In VFP I could select the data into a cursor and
then run the second select statement on the cursor. What is the best way to
get this to run properly?
Thanks.Is this what you want?
select * from (select * from table1) as table2
Raymond Yap
"Preacher Man" <nospam> wrote in message
news:%23CXITaxMGHA.2704@.TK2MSFTNGP15.phx.gbl...
> How can I run a select statement on data from a previous select statement
> within the same query? In VFP I could select the data into a cursor and
> then run the second select statement on the cursor. What is the best way
to
> get this to run properly?
> Thanks.
>|||You can use derived queries:
select col1
, col2
from ( select value1 as col1
, value2 as col2
from tbl
) tblDerived
"Preacher Man" wrote:

> How can I run a select statement on data from a previous select statement
> within the same query? In VFP I could select the data into a cursor and
> then run the second select statement on the cursor. What is the best way
to
> get this to run properly?
> Thanks.
>
>|||We can probably give a better solution if we have better specifications.
While a derived table / subquery might be the right guess, we can be more
direct if you follow http://www.aspfaq.com/5006
"Preacher Man" <nospam> wrote in message
news:%23CXITaxMGHA.2704@.TK2MSFTNGP15.phx.gbl...
> How can I run a select statement on data from a previous select statement
> within the same query? In VFP I could select the data into a cursor and
> then run the second select statement on the cursor. What is the best way
> to get this to run properly?
> Thanks.
>|||hi,
This might serve ur problem.
SELECT WWMLNM,Z3.SHCMC1,Z3.SHDOCO,Z3.SHDCTO,Z3.SHKCOO
FROM F0111
INNER JOIN
(SELECT RESLS,RESLSP,RERPCT,Z2.SHCMC1 AS SHCMC1,Z2.SHDOCO AS SHDOCO,
Z2.SHDCTO AS SHDCTO,Z2.SHKCOO AS SHKCOO,Z2.SHCMR1 AS SHCMR1
FROM F42003
INNER JOIN
(SELECT SHCMC1,SHDCTO,SHDOCO,SHKCOO,SHCMR1
FROM F4201
INNER F42003
ON SHCMC1=RESLS)Z2
ON RESLS=Z2.SHCMC1)Z3
ON wwan8=Z3.RESLSP
)SP2
bye|||An if you have SQL 2005 available then you could use a CTE.
With SubQuery as (
Select Col1 from Tab1
)
Select
a.Col2
From Tab2 a
Join SubQuery b on b.Col1 = a.Col1
Regards
Colin Dawson
www.cjdawson.com
"Preacher Man" <nospam> wrote in message
news:%23CXITaxMGHA.2704@.TK2MSFTNGP15.phx.gbl...
> How can I run a select statement on data from a previous select statement
> within the same query? In VFP I could select the data into a cursor and
> then run the second select statement on the cursor. What is the best way
> to get this to run properly?
> Thanks.
>

No comments:

Post a Comment