Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfstim82

Posted 30 October 2012 - 09:29 AM

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?

#2fstim82

Posted 30 October 2012 - 09:29 AM

I'm attempting to write a stored procedure in Migrosoft 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?

#1fstim82

Posted 30 October 2012 - 09:28 AM

I'm attempting to write a stored procedure in Migrosoft 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?

PARTNERS