I create a stored procedure that receives some parameters, and in turn these parameters are sent to another stored procedure that I call from openrowset, but I get some syntax errors.
CREATE PROCEDURE UpdatePrevFYConfigData
@startDate datetime,
@endDate datetime,
@productGroup varchar(8000) = 'All',
@projectType varchar(500) = 'All',
@businessUnit nvarchar(50) = 'All',
@developmentLocation nvarchar(100) = 'All'
AS
BEGIN
SET NOCOUNT ON;
declare @start varchar(50)
declare @end varchar(50)
set @start = cast(@startDate as varchar(40))
set @end = cast(@endDate as varchar(40))
select round(avg(a.DeviationDeadline),2) as DeviationDeadline,
round(avg(a.DeviationDefinition),2) as DeviationDefinition,
round(avg(a.DeviationRDCosts),2) as DeviationRDCosts,
round(avg(a.FunctionsAdded) + avg(a.FunctionsDeleted),2) as NotRealizedFuncs,
round(avg(a.DeviationPM2000Aufwand),2) as DeviationPM200Aufwand,
round(avg(b.Defect),2) as Defect
into
from openrowset('SQLNCLI',
'Server=.\sqlexpress;Trusted_Connection=yes;',
'SET NOCOUNT ON;SET FMTONLY OFF;EXEC [BSC_DB].dbo.SelectScorecardGraphData
'''+@start+''',
'''+@end+''',
'''+@productGroup+''',
'''+@projectType+''',
''1'',
''0'',
''All'',
''Current'',
'''+@businessUnit+''',
'''+@developmentLocation+'''
') as a,
openrowset('SQLNCLI', 'Server=.\sqlexpress;Trusted_Connection=yes;', 'SET NOCOUNT ON;SET FMTONLY OFF;EXEC [BSC_DB].dbo.GetSPCDefectDistributionData
'''+cast(@startDate as varchar(40))+''',
'''+cast(@endDate as varchar(40))+''',
''Defect'',
'''+@projectType+''',
'''+@productGroup+''',
'''+@businessUnit+''',
'''+@developmentLocation+'''') as b
update dbo.EA_ProcessScorecard_Config_Tbl
set EPC_Deviation = case EPC_Metric
when 'PM200' then (select DeviationDefinition from
when 'PM300' then (select DeviationDeadline from
when 'Cost' then (select DeviationRDCosts from
when 'PM150' then (select DeviationPM200Aufwand from
when 'Defect' then (select Defect from
when 'Funcs' then (select NotRealizedFuncs from
END
where EPC_Description = 'PrevFY' and EPC_FYYear = '0'
drop table
END
GO
I cannot create it, and I get an error:
Msg 102, Level 15, State 1, Procedure UpdatePrevFYConfigData,
Line 38 Incorrect syntax near '+'.
... but if I use hard-coded values for the parameters that it works!
Please, help!