Print Page | Close Window

SELECT and UPDATE

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=4213
Printed Date: 29 March 2026 at 7:36pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SELECT and UPDATE
Posted By: the boss
Subject: SELECT and UPDATE
Date Posted: 12 July 2003 at 4:19pm

can i use select and update commands in a single stored procedure.. if yes.. what is the appropiate code



-------------
http://www.web2messenger.com/theboss">



Replies:
Posted By: ljamal
Date Posted: 12 July 2003 at 4:59pm
yes, you can
the syntax is the same as the usage in ASP
You can use them and any other SQL statement in a stored procedure.

selects will return a recordset in the order in which the select statements appear in the stored procedure.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: stef_nz
Date Posted: 15 July 2003 at 2:38am
here is some example code from a stored proc using both select and update - ms sql server styles......

Quote create procedure dbo.UserLogin
@Username nvarchar(100),
@Password nvarchar(50),
@PID int
as
declare @UserId int
declare @SuperUserId int
select @SuperUserId = UserId
from   Users
where  IsSuperUser = 1
select @UserId = null
/* validate the user */
select @UserId = UserId
from   Users
where  Username = @Username
and    Password = @Password
if @UserId is not null
begin
  if @UserId <> @SuperUserId
  begin
    select @UserId = null
 
    select @UserId = Users.UserId
    from   UserPs
    inner join Users on UserPs.UserId = Users.UserId
    where  PID = @PID
    and    Username = @Username
    and    Password = @Password
    and    Authorized = 1
    if not @UserId is null
    begin
      update UserPs
      set    LastLoginDate = getdate()
      where  UserId = @UserId
      and    PID = @PID
    end
  end
end
select 'UserId' = @UserId

GO




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net