Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

t-sql 2008 r2 use 2 ctes

$
0
0

In existing t-sql 2008 r2 that I need to modify, there  is already an existing cte that looks like the following:
;WITH rCust AS (
         SELECT           [UserSK]                               
                                ,[structureName]
                                ,[custType]                               
                                ,[lastName]
                                ,[firstName]
                                ,[middleName]
                               ,[suffix]
                FROM
    [DataStore].[dbo].[vwBridgeUser]

  WHERE
   custType = @custType   
)

I would like to add the following cte so I can remove the hard-code year values.
;WITH  sYear AS (
 SELECT   [CustSK],[startYear],[endYear]
 FROM DimCustCalendarYear
  where DimCustCalendarYear.active = 1
)

The both ctes do not reference each other. They are used in separate parts of the sql.
Thus I have the following questions:

1. Can you show me sql and or point me to a reference that shows me how to use 2 cte's in the same sql?
2. If 2 cte's can not be used in the same sql, would you explain to me how I would solve my problem or possibly show
   me some alternative that would solve my problem? Would I need to use temp tables, temp variables, view, function, or
   what?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>