Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


sql help needed


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 fstim82   Members   -  Reputation: 132

Like
0Likes
Like

Posted 30 October 2012 - 09:28 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?

Edited by fstim82, 30 October 2012 - 09:29 AM.


Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 6248

Like
0Likes
Like

Posted 30 October 2012 - 10:14 AM

SELECT
CASE isGuest
WHEN 0 THEN SET @Guest = 0
ELSE SET @Guest = 1
END
FROM
dbo.Account
WHERE
AccountId = @AccountId;
The problem at the moment is that there is incorrect syntax near the SET, ELSE, and FROM keywords


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

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

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

gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=

#3 fstim82   Members   -  Reputation: 132

Like
0Likes
Like

Posted 30 October 2012 - 01:01 PM

Awesome. Thanks a ton!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS