您是否可以将SELECT INTO语句与包含UDF的CTE一起使用?

时间:2012-04-12 19:52:27

标签: select user-defined-functions common-table-expression

我可以这样做:

With ZipCodeCTE as
            {
            select nvl(HH.GeoUSZip5 , **ZipCodeKeyLookUp**(HH.[CityName],HH.[StateName])) as TotalZipCode
            from ODSDataArchive.archive.HHJob_Data_201202 HH
            }
    /* This Is a SELECT INTO statement that inserts
       data into [Jobs].[dbo].[FactRPP]*/
    SELECT  [dbo].[FactJobsDaily].jobdid, 
            [dbo].[FactJobsDaily].DateKey,
            [dbo].[FactJobsDaily].YearMonth,
            [dbo].[FactJobsDaily].AccountKey,
            [dbo].[FactJobsDaily].BridgeSocKey,
            [dbo].[FactJobsDaily].HostSiteKey,
            [dbo].[FactJobsDaily].JobClickedCount,
            [dbo].[FactJobsDaily].JobResultsPageCount,
            (select DZ.ZipCodeKey 
               from dimensions.dbo.DimZipCode DZ
              where DZ.ZipCodeKey IN 
                               (Select CAST(TotalZipCode AS INT) 
                                 from ZipCodeCTE))
      INTO [Jobs].[dbo].[FactRPP]                                
      from dbo.FactJobsDaily  
           inner join ODSDataArchive.archive.HHJob_Data_201202  
                   on dbo.FactJobsDaily.JobDID = ODSDataArchive.archive.HHJob_Data_201202.DID  
                   and dbo.FactJobsDaily.datekey = ODSDataArchive.archive.HHJob_Data_201202.datekey 
           inner join dimensions.dbo.Dimzipcode dzc 
                   on ODSDataArchive.archive.HHJob_Data_201202.geoUSZip5 = dimensions.dbo.Dimzipcode.ZipCode
     where [dbo].[FactJobsDaily].yearmonth= 201202 
           and [dbo].[FactJobsDaily].isactivekey = 1 
         --  and ODSDataArchive.archive.HHJob_Data_201202.geoUSZip5  <> '' 
         --  and ODSDataArchive.archive.HHJob_Data_201202.geoUSZip5  IS NOT NULL
           and ODSDataArchive.archive.HHJob_Data_201202.status = 0 
           and ODSDataArchive.archive.HHJob_Data_201202.CountryName = 'US' 
    order by [dbo].[FactJobsDaily].jobdid;

1 个答案:

答案 0 :(得分:1)

因为CTE转换为常规查询,所以简短答案是肯定的。