调用带有反斜杠的架构的过程

时间:2019-10-25 00:42:32

标签: sql-server backslash

我在https://stackoverflow.com/questions/ask中尝试了该解决方案,但没有成功,所以我问一个新问题:

我知道这不是可复制的示例。

EXEC
mhg\EDW_TM_DSA_CR_Nonemployee.O_E  @data     =   "[Reporting].[mhg\EDW_TM_DSA_CR_Nonemployee].emergencyDx_O_E_data",
   @subject   =   "PersonID",
   @feature   =   "NomenclatureID",
   @target    =   "cohort"
GO
  

消息103010,第16级,状态1,第1行   在第2行,第2列,第4行分析错误:“ \”附近的语法不正确。

我认为我的架构名称中的反斜杠引起错误。

CREATE PROC [mhg\EDW_TM_DSA_CR_Nonemployee].O_E 
-- Identify the relationship between two class variables where
-- It is desired to know what levels of feature predicts target
-- in the data set data with subeject subject subject.
-- Currently the Observed over Expected is calculated from the data
-- Using assumming a gamma distribution with prior of alpha = 10 and beta = 10.

   @data    nvarchar(128),
   @subject   nvarchar(128),
   @feature  nvarchar(128),
   @target nvarchar(128)
AS

BEGIN

SET NOCOUNT ON;
DECLARE @cmd NVARCHAR(max)

set @cmd = '
with person
as
(
   select count(distinct [' + @subject + '] ) as count_person, [' + @feature + '] , [' + @target + '] 
   from ' +  @data +
   ' group by [' + @feature + '] , [' + @target + ']
   )
,
target  
as
(
   select count(distinct [' + @subject + '] ) as count_target, [' + @target + '] 
   from ' +  @data +
   ' group by [' + @target + '] 
)
,
feature 
as
(
 select count(distinct [' + @subject + '] ) as count_feature, [' + @feature + '] 
   from ' +  @data +
   ' group by [' + @feature + '] 
)
,
totn
as 
(
   select count(distinct [' + @subject + '] ) as count_tot 
   from ' +  @data +
   ' )



SELECT  a.[' + @feature + '] , a.[' + @target + '] , 
        a.count_person, c.count_feature,
       b.count_target, d.count_tot,
       a.count_person  as observed,
       (1.0 *c.count_feature * b.count_target )/(1.0 * d.count_tot) as expected,
       (a.count_person/(c.count_feature + .001))/((b.count_target + .001)/d.count_tot) as RR,
       (a.count_person + 10.0) / (1.0 * b.count_target * c.count_feature/d.count_tot + 10.0) as O_E_adj

FROM Person as a
JOIN target  as b
on a.[' + @target + '] = b.[' + @target + ']
JOIN feature  as c
on a.[' + @feature + '] = c.[' + @feature + '] 
CROSS join totn as d
order by O_E_adj desc
'
EXEC sp_executesql @cmd
END
GO

0 个答案:

没有答案