Click to See Complete Forum and Search --> : SQL Stored Procedures


Bondorofi
03-26-2007, 01:38 PM
Hi all,

I am using Microsoft SQL Management Server Studio 2005
I am trying to construct a Stored Procedure as indicated below but am getting the following error

Msg 156, Level 15, State 1, Procedure GrabDBX, Line 15
Incorrect syntax near the keyword 'CASE'.
Msg 156, Level 15, State 1, Procedure GrabDBX, Line 25
Incorrect syntax near the keyword 'FROM'.

I will appreciate any help with this problem

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[getme] (
@xxxxxxx INT,
@myrole INT
)
AS
BEGIN

CASE WHEN
CASE WHEN ([myrole] = 7 or [myrole] = 1) THEN
SELECT

.................
END

CASE WHEN
..........
END

FROM ...............

END;

mattyblah
03-26-2007, 03:30 PM
You need to be using IF statements

IF (condition)
BEGIN
END

CASE is used in queries. Where are you getting [myrole]? Are you posting the entire stored proc?