Ok, I checked everything. Everything matches and still it doesn't work. I don't see any reason.
It still doesn't like else part of my stored procedure.
The code works fine if I remove else part from stored procedure. I am posting the whole stored procedure here if somebody can figure out the problem.
CREATE Procedure dbo.Cycle_Packing_ListApp
@IsDistrict as bit,
@County_Shipment_Type as varchar(50)
AS
IF @IsDistrict = 1
SELECT * FROM orPackingList --This is a view
ELSE
IF @County_Shipment_Type = 'Cycle I'
SELECT DISTINCT '' AS FormSortOrder,
Counties.County_Name, Counties.County_Key, 0 AS Dis_Key, '' AS Dis_Name, 0 AS Dis_Num,
'' AS SchoolName, 0 as School_Key, 0 as School_Num, Counties.CDS,
County_Key AS Order_Key, 'Score Reports' AS OrderType, Products.[Description], 1 AS Quantity,
Products.Product_Key, Products.Display_Order, 1 as address_location,
Counties.CSuperTitle AS Title, Counties.CSuperFName AS FName, Counties.CSuperLName AS LName,
Counties.CSuperBulkBuild AS Build,
Counties.CSuperBulkStreet AS Street, Counties.CSuperBulkCity AS City, Counties.CSuperBulkZip AS Zip,
Counties.CSuperPhone AS Phone, Counties.CSuperExt AS Ext
FROM Products
CROSS JOIN Counties
WHERE Product_Key IN (1104, 1105, 1110, 1114)
AND County_Key NOT IN (90)
ELSE IF @County_Shipment_Type = 'Cycle II'
SELECT DISTINCT '' AS FormSortOrder,
Counties.County_Name, Counties.County_Key, 0 AS Dis_Key, '' AS Dis_Name, 0 AS Dis_Num,
'' AS SchoolName, 0 as School_Key, 0 as School_Num, Counties.CDS,
County_Key AS Order_Key, 'Score Reports' AS OrderType, Products.[Description], 1 AS Quantity,
Products.Product_Key, Products.Display_Order, 1 as address_location,
Counties.CSuperTitle AS Title, Counties.CSuperFName AS FName, Counties.CSuperLName AS LName,
Counties.CSuperBulkBuild AS Build,
Counties.CSuperBulkStreet AS Street, Counties.CSuperBulkCity AS City, Counties.CSuperBulkZip AS Zip,
Counties.CSuperPhone AS Phone, Counties.CSuperExt AS Ext
FROM Products
CROSS JOIN Counties
WHERE Product_Key IN (1210,1211,1212,1213,1214,1215,1216,1240)
AND County_Key NOT IN (43,45,47,90)
ELSE IF @County_Shipment_Type = 'Prep Materials'
SELECT DISTINCT '' AS FormSortOrder,
Counties.County_Name, Counties.County_Key, 0 AS Dis_Key, '' AS Dis_Name, 0 AS Dis_Num,
'' AS SchoolName, 0 as School_Key, 0 as School_Num, Counties.CDS,
County_Key AS Order_Key, 'Prep Materials' AS OrderType, Products.[Description], 2 AS Quantity,
Products.Product_Key, Products.Display_Order, 1 as address_location,
Counties.CTCTitle AS Title, Counties.CTCFName AS FName, Counties.CTCLName AS LName,
Counties.CTCBulkBuild AS Build,
Counties.CTCBulkStreet AS Street, Counties.CTCBulkCity AS City, Counties.CTCBulkZip AS Zip,
Counties.CTCPhone AS Phone, Counties.CTCExt AS Ext
FROM Products
CROSS JOIN Counties
WHERE Product_Key IN (1401, 1403)
ELSE IF @County_Shipment_Type = 'SRA'
SELECT DISTINCT '' AS FormSortOrder,
Counties.County_Name, Counties.County_Key, 0 AS Dis_Key, '' AS Dis_Name, 0 AS Dis_Num,
'' AS SchoolName, 0 as School_Key, 0 as School_Num, Counties.CDS,
Counties.County_Key AS Order_Key, 'SRA' AS OrderType, Products.[Description],
Case WHEN Product_Key = 1501 THEN Ceiling((Count(Distinct School_Key) + 1.0)/25.0)*25 ELSE Ceiling((Count(Distinct School_Key) + 1.0)/25.0) END AS Quantity,
Products.Product_Key, Products.Display_Order, 1 as address_location,
Counties.CSuperTitle AS Title, Counties.CSuperFName AS FName, Counties.CSuperLName AS LName,
Counties.CSuperBulkBuild AS Build,
Counties.CSuperBulkStreet AS Street, Counties.CSuperBulkCity AS City, Counties.CSuperBulkZip AS Zip,
Counties.CSuperPhone AS Phone, Counties.CSuperExt AS Ext
FROM Products
CROSS JOIN Counties
INNER JOIN Districts
ON Districts.County_Key = Counties.County_Key
INNER JOIN dbo.Schools
ON Schools.Dist_Key = Districts.Dis_Key
WHERE Product_Key IN (1501,1503)
AND Schools.inactive = 0 and districts.inactive = 0
AND Counties.County_Key NOT IN (43,45,47,90)
GROUP BY Counties.County_Name, Counties.County_Key, Counties.CDS, Counties.County_Key,
Products.Description, Products.Product_Key, Products.Display_Order,
Counties.CSUPERTitle, Counties.CSUPERFName, Counties.CSUPERLName,
Counties.CSUPERBulkBuild, Counties.CSUPERBulkStreet, Counties.CSUPERBulkCity,
Counties.CSUPERBulkZip, Counties.CSUPERPhone, Counties.CSUPERExt
ORDER BY Counties.County_Key
The wiew orPackingList is...
CREATE VIEW dbo.orPackingList AS
SELECT DISTINCT Case OrderType WHEN 'Standalone' THEN FormSortOrder_FT ELSE FormSortOrder END AS FormSortOrder,
Counties.County_Name, Counties.County_Key, Districts.Dis_Key, Districts.Dis_Name, Districts.Dis_Num,
CASE Schools.School_Name WHEN 'DistrictOverage' THEN 'A' ELSE Schools.School_Name END AS SchoolName, Schools.School_Key, Schools.School_Num, Schools.CDS,
Orders.Order_Key, Orders.OrderType, Products.[Description], Order_Details.Quantity, Products.Product_Key, Products.Display_Order, Orders.address_location,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSATitle WHEN 2 THEN TCTitle WHEN 3 THEN Extra1_Title END As Title,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSAFName WHEN 2 THEN TCFName WHEN 3 THEN Extra1_FName END As FName,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSALName WHEN 2 THEN TCLName WHEN 3 THEN Extra1_LName END As LName,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSABulkBuild WHEN 2 THEN TCBulkBuild WHEN 3 THEN Extra1_Build END As Build,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSABulkStreet WHEN 2 THEN TCBulkStreet WHEN 3 THEN Extra1_Street END As Street,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSABulkCity WHEN 2 THEN TCBulkCity WHEN 3 THEN Extra1_City END As City,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSABulkZip WHEN 2 THEN TCBulkZip WHEN 3 THEN Extra1_Zip END As Zip,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSAPhone WHEN 2 THEN TCPhone WHEN 3 THEN Extra1_Phone END As Phone,
CASE Orders.Address_Location WHEN 1 THEN Districts.CSAExt WHEN 2 THEN TCExt WHEN 3 THEN Extra1_Ext END As Ext
FROM Order_Details
INNER JOIN Orders ON Order_Details.Order_Key = Orders.Order_Key
INNER JOIN nCounts ON Orders.nCount_Key = nCounts.nCount_Key
INNER JOIN Products ON Order_Details.Product_Key = Products.Product_Key
INNER JOIN Schools ON nCounts.School_Key = Schools.School_Key
INNER JOIN Districts ON Schools.Dist_Key = Districts.Dis_Key
INNER JOIN Counties ON Counties.County_Key = Districts.County_Key
WHERE Order_Details.Quantity > 0 AND IsFilled = 0 AND Orders.IsCancelled = 0
I will really appreciate if somebody can figure out the problem before I give up on this.
Thanks,
ndp