common table expression - sql parameterised cte query -


i have query following

select  *         (                select   *                    calltablefunction(@paramprev)                 .....< whole load of other joins, wheres , etc >........             ) prevvalues             full join             (                 select  *                    calltablefunction(@paramcurr)                 .....< whole load of other joins, wheres , etc >........             ) currvalues                on prevvalues.field1 = currvalues.field1             ....<other joins same subselect above 2 different parameters passed in       ........ group    .... 

the following subselect common subselects in query bar @param table function.

        select  *            calltablefunction(@param)             .....< whole load of other joins, wheres , etc >........ 

one option me convert function , call function, dont may changing subselect query quite for.....or wondering if there alternative using cte like

with sometable(@param1)  (         select  *            calltablefunction(@param)                 .....< whole load of other joins, wheres , etc >........ ) select               sometable(@paramprev)       prevvalues         full join sometable(@currprev)  currvalues  on prevvalues.field1 = currvalues.field1       ........ group    .... 

is there syntax or technique can use this.

this in sql server 2008 r2

thanks.

what you're trying not supported syntax - cte's cannot parameterised in way.

see books online - http://msdn.microsoft.com/en-us/library/ms175972.aspx.

(values in brackets after cte name optional list of output column names)

if there 2 parameter values (paramprev , currprev), might able make code little easier read splitting them 2 ctes - this:

with prevcte  (           select  *              calltablefunction(@paramprev)                   .....< whole load of other joins, wheres , etc   ........ ) ,curcte  (           select  *              calltablefunction(@currprev)                   .....< whole load of other joins, wheres , etc   ........ ),  select                 prevcte       prevvalues           full join curcte  currvalues  on   prevvalues.field1 = currvalues.field1   ........ group     .... 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -