CREATE procedure [dbo].[up_get_auth_id] @bcust_id nvarchar(50), @UUID uniqueidentifier, @channelling int, @mac_addr char(17), @mac_addr02 char(17), @mac_addr03 char(17) as set nocount on declare @login_count bigint set @login_count = -1 if exists (select AuthID from AuthTable with (nolock) where WindyCode = @bcust_id) begin select @login_count = [LCount] from AuthTable with (nolock) where WindyCode = @bcust_id select AuthID, online, DBCIndex, InquiryCount, CashMileage, [pc_room_point] from AuthTable with (nolock) where WindyCode = @bcust_id --Online Login Count update AuthTable set [online] = '1', [LCount] = @login_count+1, ServerType = 'G', ServerIP=0, HostID=0, mac_addr=@mac_addr, mac_addr02=@mac_addr02, mac_addr03=@mac_addr03 from AuthTable where WindyCode = @bcust_id return; end declare @LastAuthID bigint; select @LastAuthID = [Value] from GlobalVariableTable with (nolock) where VarName = 'LastAuthID' update GlobalVariableTable set [Value] = @LastAuthID+1 where VarName = 'LastAuthID' insert into AuthTable values( @bcust_id, 0, @UUID, @LastAuthID, '1', GetDate(), GetDate(), GetDate(), 0, 1, 0, 'G', 0, -1, 5, 0, 0, @channelling, 0, 0, @mac_addr, @mac_addr02, @mac_addr03, '' ) select AuthID, online, DBCIndex, InquiryCount, CashMileage, [pc_room_point] from AuthTable with (nolock) where WindyCode = @bcust_id return @@error