S
Subir Kumar
Hi,
I am writing a stored procedure in SQL Server,but it keeps
on giving me the same error everytime "Invalid column
name: FirstOfSub Product Code
Have tried to change it to FirstProductCode, but it still
pops the same error.
Would be grateful if you could advise me on this.
Thank you,
Regards,
Subir
CREATE PROCEDURE MTDTest
@strReportClient varchar(255)
AS
IF NOT EXISTS( SELECT 1 FROM sysobjects WHERE NAME
= 'TempMTDReport' )
CREATE TABLE TempMTDReport (
[Product Code] NVARCHAR(255) DEFAULT NULL,
[FirstOfProduct Name] NVARCHAR(255) DEFAULT NULL,
[Sub Product Code] NVARCHAR(255) DEFAULT NULL,
[FirstOfSub Product Code] NVARCHAR(255) DEFAULT NULL,
[Report Client] NVARCHAR(255) DEFAULT NULL ,
[FirstOfUnit Of Measure] NVARCHAR(255) DEFAULT NULL,
[FirstOfUnit Price] MONEY(8) ,
Volume2 FLOAT(10) DEFAULT 0.0 ,
[SumOfTotal Price] FLOAT(10) DEFAULT 0.0,
[Billing Cycle Name] SmallDateTime DEFAULT NULL )
Insert TempMTDReport ([Product Code], [FirstOfProduct
Name], [Sub Product Code], [FirstOfSub Product Name],
[Report Client],[FirstOfUnit Of Measure], [FirstOfUnit
Price], Voulme2, [SumOfTotal Price],[Billing Cycle Name])
SELECT dbo.tblCurrentMonth.[Product Code],
MAX(dbo.tblCurrentMonth.[Product Name]) AS
[FirstOfProduct Name],
dbo.tblCurrentMonth.[Sub Product Code],
MAX(dbo.tblCurrentMonth.[Sub
Product Name]) AS [FirstOfSub Product Name],
dbo.tblExpenseCodes.[Report Client],
MAX(dbo.tblCurrentMonth.[Unit Of
Measure]) AS [FirstOfUnit Of Measure],
MAX(dbo.tblCurrentMonth.[Unit Price]) AS
[FirstOfUnit Price],
SUM(CASE WHEN
(dbo.tblCurrentMonth.Volume = 0) THEN 1 ELSE [Volume] END)
AS Volume2,
SUM(dbo.tblCurrentMonth.[Total Price]) AS
[SumOfTotal Price],
dbo.tblCurrentMonth.[Billing Cycle Name]
FROM dbo.tblExpenseCodes INNER JOIN
dbo.tblCurrentMonth LEFT OUTER JOIN
dbo.tblSubProductDesc ON
dbo.tblCurrentMonth.[Sub Product Code] =
dbo.tblSubProductDesc.[Subproduct Code] ON
dbo.tblExpenseCodes.[long code] =
dbo.tblCurrentMonth.[Long Code]
WHERE (dbo.tblExpenseCodes.[Report Client] =
@strReportClient)
GROUP BY dbo.tblCurrentMonth.[Product Code],
dbo.tblCurrentMonth.[Sub Product Code],
dbo.tblExpenseCodes.[Report Client],
dbo.tblCurrentMonth.[Unit Of
Measure], dbo.tblCurrentMonth.[Billing Cycle Name],
dbo.tblCurrentMonth.[Sub Product Name],
dbo.tblCurrentMonth.[Product Name]
GO
I am writing a stored procedure in SQL Server,but it keeps
on giving me the same error everytime "Invalid column
name: FirstOfSub Product Code
Have tried to change it to FirstProductCode, but it still
pops the same error.
Would be grateful if you could advise me on this.
Thank you,
Regards,
Subir
CREATE PROCEDURE MTDTest
@strReportClient varchar(255)
AS
IF NOT EXISTS( SELECT 1 FROM sysobjects WHERE NAME
= 'TempMTDReport' )
CREATE TABLE TempMTDReport (
[Product Code] NVARCHAR(255) DEFAULT NULL,
[FirstOfProduct Name] NVARCHAR(255) DEFAULT NULL,
[Sub Product Code] NVARCHAR(255) DEFAULT NULL,
[FirstOfSub Product Code] NVARCHAR(255) DEFAULT NULL,
[Report Client] NVARCHAR(255) DEFAULT NULL ,
[FirstOfUnit Of Measure] NVARCHAR(255) DEFAULT NULL,
[FirstOfUnit Price] MONEY(8) ,
Volume2 FLOAT(10) DEFAULT 0.0 ,
[SumOfTotal Price] FLOAT(10) DEFAULT 0.0,
[Billing Cycle Name] SmallDateTime DEFAULT NULL )
Insert TempMTDReport ([Product Code], [FirstOfProduct
Name], [Sub Product Code], [FirstOfSub Product Name],
[Report Client],[FirstOfUnit Of Measure], [FirstOfUnit
Price], Voulme2, [SumOfTotal Price],[Billing Cycle Name])
SELECT dbo.tblCurrentMonth.[Product Code],
MAX(dbo.tblCurrentMonth.[Product Name]) AS
[FirstOfProduct Name],
dbo.tblCurrentMonth.[Sub Product Code],
MAX(dbo.tblCurrentMonth.[Sub
Product Name]) AS [FirstOfSub Product Name],
dbo.tblExpenseCodes.[Report Client],
MAX(dbo.tblCurrentMonth.[Unit Of
Measure]) AS [FirstOfUnit Of Measure],
MAX(dbo.tblCurrentMonth.[Unit Price]) AS
[FirstOfUnit Price],
SUM(CASE WHEN
(dbo.tblCurrentMonth.Volume = 0) THEN 1 ELSE [Volume] END)
AS Volume2,
SUM(dbo.tblCurrentMonth.[Total Price]) AS
[SumOfTotal Price],
dbo.tblCurrentMonth.[Billing Cycle Name]
FROM dbo.tblExpenseCodes INNER JOIN
dbo.tblCurrentMonth LEFT OUTER JOIN
dbo.tblSubProductDesc ON
dbo.tblCurrentMonth.[Sub Product Code] =
dbo.tblSubProductDesc.[Subproduct Code] ON
dbo.tblExpenseCodes.[long code] =
dbo.tblCurrentMonth.[Long Code]
WHERE (dbo.tblExpenseCodes.[Report Client] =
@strReportClient)
GROUP BY dbo.tblCurrentMonth.[Product Code],
dbo.tblCurrentMonth.[Sub Product Code],
dbo.tblExpenseCodes.[Report Client],
dbo.tblCurrentMonth.[Unit Of
Measure], dbo.tblCurrentMonth.[Billing Cycle Name],
dbo.tblCurrentMonth.[Sub Product Name],
dbo.tblCurrentMonth.[Product Name]
GO