Вызовите процедуру со схемой, в которой есть обратная косая черта - PullRequest
0 голосов
/ 25 октября 2019

Я попробовал решение в 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, столбец: 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

...