Hi
Can someone help? This query isn't working when i make it a stored procedure!!!
Maybe i have less inverted commas / quotation marks
ALTER PROC spVM
(
@Table_Name sysname,
@Table_Name2 sysname
)
AS
BEGIN
SET NOCOUNT OFF;
DECLARE @Dynamictbl nvarchar(255)
SET @Dynamictbl =
N'SELECT DISTINCT
t1.[Projektdefinition DB] AS [Projektdefinition DB 201409BS],
t1.[Projektdefinition DB1] AS [Projektbezeichung DB 201409BS],
t1.[GWU Vorschau mit AZ] AS [GWU_Per201409BS_IST],
t2.[GWU Vorschau mit AZ] AS [GWU_Per201408BS IST],
t1.[GWU Vorschau mit AZ] - t2.[GWU Vorschau mit AZ] AS [GWU IST DELTA],
t1.[GWU Planung mit AZ] AS [GWU Per201409BS SOLL],
t2.[GWU Planung mit AZ] AS [GWU_SOLL],
t1.[GWU Planung mit AZ] - t2.[GWU Planung mit AZ] AS [GWU SOLL DELTA],
t1.[IST Vorjahre mit AZ] AS [Ist Vorjahre],
t2.[IST Vorjahre mit AZ] AS [Ist Vorjahre],
t1.[Ist Vorjahr mit AZ] AS [Ist Vorjahr],
t2.[Ist Vorjahr mit AZ] AS [Ist Vorjahr],
t1.[IST lfd#GJ mit AZ] AS [Ist lfd GJ],
t2.[IST lfd#GJ mit AZ] AS [Ist lfd GJ],
t1.[Obligo BANF lfd# GJ] AS [Obligo BANF Ifd GJ],
t2.[Obligo BANF lfd# GJ] AS [Obligo BANF Ifd GJ],
t1.[Vorschau lfd# GJ mit AZ] AS [Vorschau Ifd GJ],
t2.[Vorschau lfd# GJ mit AZ] AS [Vorschau Ifd GJ],
t1.[Vorschau Folgejahr mit AZ] AS [Vorschau Folgejahr],
t2.[Vorschau Folgejahr mit AZ] AS [Vorschau Folgejahr],
t1.[Vorschau GJ+02 mit AZ] AS [Vorschau GJ+02],
t2.[Vorschau GJ+02 mit AZ] AS [Vorschau GJ+02],
t1.[Vorschau GJ+03 mit AZ] AS [Vorschau GJ+03],
t2.[Vorschau GJ+03 mit AZ] AS [Vorschau GJ+03],
t1.[Vorschau GJ+04 mit AZ] AS [Vorschau GJ+04],
t2.[Vorschau GJ+04 mit AZ] AS [Vorschau GJ+04],
t1.[Vorschau GJ+05 mit AZ] AS [Vorschau GJ+05],
t2.[Vorschau GJ+05 mit AZ] AS [Vorschau GJ+05],
t1.[Vorschau GJ+06 mit AZ] AS [Vorschau GJ+06],
t2.[Vorschau GJ+06 mit AZ] AS [Vorschau GJ+06],
t1.[Vorschau GJ+07 mit AZ] AS [Vorschau GJ+07],
t2.[Vorschau GJ+07 mit AZ] AS [Vorschau GJ+07],
t1.[Planung GJ+06 mit AZ] AS [Planung GJ+06],
t2.[Planung GJ+06 mit AZ] AS [Planung GJ+06],
t1.[IST lfd# GJ zum Obligostichtag mit AZ] AS [Obligostichtag],
t2.[IST lfd# GJ zum Obligostichtag mit AZ] AS [Obligostichtag]
FROM ' + @Table_Name + ' AS t1
LEFT OUTER JOIN ' + @Table_Name2 + ' AS t2
ON t1.[Projektdefinition DB] = t2.[Projektdefinition DB]
WHERE t1.[Geschäftsbereich] = ''PB'' AND t2.[Geschäftsbereich] = ''PB''' +
' ORDER BY t1.[Projektdefinition DB] ASC '
EXECUTE sp_executesql @Dynamictbl
END
GO
EXEC spVM 'tbl2', 'tbl1'