Question : CASE Statement in SELECT

Experts,

In the attached code, I'm trying to include a WHERE clause in my query only if @RoomID is not zero.  The compiler doesn't like the query.  What am I doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spScheduleRoomPopulate')
	BEGIN
		DROP  Procedure  spScheduleRoomPopulate 
	END

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
  CREATE PROCEDURE [dbo].[spScheduleRoomPopulate]
	@RoomID int
  AS
  SET NOCOUNT ON

--ALTER TABLE ScheduleRoom NOCHECK CONSTRAINT ALL
DELETE FROM ScheduleRoom
--ALTER TABLE ScheduleRoom CHECK CONSTRAINT ALL



SET IDENTITY_INSERT ScheduleRoom ON 

INSERT INTO ScheduleRoom
(
	ScheduleRoomID
	,ScheduleCenterID
	,ScheduleRuleCode
)
SELECT 
AssessmentCenterRoomID 
,AssessmentCenterID
,'STANDARD ALL WEEK'
FROM AssessmentCenterRoom 
SELECT CASE  
	WHEN @RoomID <> 0 THEN
		WHERE AssessmentCenterRoomID=@RoomID	
END

SET IDENTITY_INSERT ScheduleRoom OFF

Answer : CASE Statement in SELECT

you cannot "build" a sql statement using a case statement.

you CAN have a case statement as part or a sql statement, aka like this, much more unreadable:
1:
2:
3:
4:
5:
6:
SELECT
AssessmentCenterRoomID
,AssessmentCenterID
,'STANDARD ALL WEEK'
FROM AssessmentCenterRoom
WHERE CASE WHEN @RoomID = 0 THEN AssessmentCenterRoomID ELSE @RoomID END = AssessmentCenterRoomID
Random Solutions  
 
programming4us programming4us