ms access - Reuse subquery results for other computations with SQL Server -


i have set of queries 1 in access run fine, when try make them either view or stored procedure in ms sql, tells me subquery's alias not valid column use later in query run calculation on.

here's have in access:

select t.districtnum,  (select count(winner) tournygames2013 type='pool 1' , winner=t.districtnum) teamwins,  (select count(loser) tournygames2013 type='pool 1' , loser=t.districtnum) teamloses, ([teamwins]+[teamloses]) gametotal tournyteams2013 t t.pool=1 

how in world make view or stored procedure works?
thanks, gentle, first post here.

in sql server (as other databases adhere ansi standard), cannot reference alias @ same level of select defined.

you can fix using subquery:

select t.*, ([teamwins]+[teamloses]) gametotal (select t.districtnum,              (select count(winner) tournygames2013 type='pool 1' , winner=t.districtnum) teamwins,               (select count(loser) tournygames2013 type='pool 1' , loser=t.districtnum) teamloses       tournyteams2013 t       t.pool=1      ) t 

Comments