Sign in to follow this  

sql help needed

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm attempting to write a stored procedure in Microsoft SQL Server Management Studio Express 2005 version 9.00.2047.00. I have no SQL experience, but I've managed to come up with this so far:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteGuestAccount]
@AccountId int
AS
BEGIN
DECLARE @Guest bit;
SET @Guest = 0;
-- First make sure its a guest account.
SELECT
CASE isGuest
WHEN 0 THEN SET @Guest = 0
ELSE SET @Guest = 1
END
FROM
dbo.Account
WHERE
AccountId = @AccountId;
IF @Guest = 1
BEGIN
-- Delete table entries.
DELETE FROM dbo.Account
WHERE AccountId=@AccountId;
DELETE FROM dbo.AvatarListSecond
WHERE OwnerId=@AccountId;
DELETE FROM dbo.BanAndUnChat
WHERE AccountId=@AccountId;
...
END
END


The problem at the moment is that there is incorrect syntax near the SET, ELSE, and FROM keywords. Can anyone tell me based on what I've written here what I'm supposed to have? Edited by fstim82

Share this post


Link to post
Share on other sites
[quote name='fstim82' timestamp='1351610900' post='4995450']
[code]
SELECT
CASE isGuest
WHEN 0 THEN SET @Guest = 0
ELSE SET @Guest = 1
END
FROM
dbo.Account
WHERE
AccountId = @AccountId;
[/code]
The problem at the moment is that there is incorrect syntax near the SET, ELSE, and FROM keywords
[/quote]

If the type of [dbo].[Account].[isGuest] is [tt]bit[/tt], try:
[code]
select @Guest = isGuest
from dbo.Account
where AccountId = @AccountId
[/code]

Otherwise:
[code]
select @Guest = case isGuest when 0 then 0 else 1 end
from dbo.Account
where AccountId = @AccountId
[/code]

Or even:
[code]
select @Guest = cast( isGuest as bit )
from dbo.Account
where AccountId = @AccountId
[/code]

Share this post


Link to post
Share on other sites

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this