question

paresh avatar image
paresh asked

case statement - not working

Hi,

I am having a hard time in making case expression,

I have created a Stored Procedure and testing it, but it is not working.

Shows

Msg 156, Level 15, State 1, Line 76
Incorrect syntax near the keyword 'and'.
Msg 156, Level 15, State 1, Line 76
Incorrect syntax near the keyword 'and'

select ReportingUnit,SUM(UsedQuantity) as SumOfUsedQuantity,
case when ReportingUnit=1
then (select COUNT(Id) from FloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=2
then (select COUNT(Id) from FlatsPerFloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=3
then (select COUNT(Id) from ColumnsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=4
then (select COUNT(Id) from FootingsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=5
then 1 end as TotalFlat,
case when (CAST(SUM(UsedQuantity) as decimal(18,2))/CAST((
case when ReportingUnit=1
then (select COUNT(Id) from FloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=2
then (select COUNT(Id) from FlatsPerFloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=3
then (select COUNT(Id) from ColumnsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=4
then (select COUNT(Id) from FootingsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=5
then 1 end
) as decimal(18,2))) <= 100 then ((CAST(SUM(UsedQuantity) as decimal(18,2))/CAST((
case when ReportingUnit=1
then (select COUNT(Id) from FloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=2
then (select COUNT(Id) from FlatsPerFloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=3
then (select COUNT(Id) from ColumnsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=4
then (select COUNT(Id) from FootingsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=5
then 1 end
) as decimal(18,2)))) ELSE 100 END as WorkCompletion,(select ISNULL(SUM(ISNULL(PercentageWeightage,0)),0) from BuildingWiseSubActivityWeightage where BuildingId=fullData.BuildingID and BuildingWiseSubActivityWeightage.SubActivityId=fullData.SubActivityId) as PercentageWeightage,
CAST((
case when CAST(SUM(UsedQuantity) as decimal(18,2))/CAST((

case when ReportingUnit=1
then (select COUNT(Id) from FloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=2
then (select COUNT(Id) from FlatsPerFloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=3
then (select COUNT(Id) from ColumnsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=4
then (select COUNT(Id) from FootingsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=5
then 1 end
) as decimal(18,2)) <= 100 then CAST(SUM(UsedQuantity) as decimal(18,2))/CAST((

case when ReportingUnit=1
then (select COUNT(Id) from FloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=2
then (select COUNT(Id) from FlatsPerFloorBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=3
then (select COUNT(Id) from ColumnsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=4
then (select COUNT(Id) from FootingsBuildingMaster where BuildingID=fullData.BuildingID)
when ReportingUnit=5
then 1 end
) as decimal(18,2))
ELSE 100 END * (select ISNULL(SUM(ISNULL(PercentageWeightage,0)),0) from BuildingWiseSubActivityWeightage
where BuildingId=fullData.BuildingID and BuildingWiseSubActivityWeightage.SubActivityId=fullData.SubActivityId)/100
)as decimal(18,2)) as Progress,SubActivityId,ActivityId,BuildingId into #temp3 from fullData group by SubActivityId,ActivityId,fullData.BuildingId,fullData.ReportingUnit;

case-statement
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

WRBI avatar image WRBI commented ·

In the text box editor please use the CODE button and put you're code in there. It formats it nicely for others to read. Thank you.

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.