Stored Procedures [dbo].[UpdateCurrentDriverName]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inOrderIDint4
@inChangedBySysUserIDint4
@inUpdateSourcevarchar(128)128
@inDriverSysUserIDint4
@inDriverNamevarchar(64)64
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/*
* Sets or clears the OrdersExtended.CurrentDriver field (name of the driver, which might not be "our" driver).
*
* @inOrderID: Required: the primary key for the order.
* @inChangedBySysUserID: Optional: The user making the change (defaults to the External Application user if not specified.
* @inUpdateSource: Optional The source of the update (defaults to 'Unspecified Van Line Download').
* @inDriverSysUserID: The SysUserID of the driver when the driver is a company driver.
* @inDriverName: The name of the driver when the driver is not a company driver.
*/

CREATE PROCEDURE [dbo].[UpdateCurrentDriverName]
    @inOrderID int,
    @inChangedBySysUserID int = null,
    @inUpdateSource varchar(128) = null,
    @inDriverSysUserID int = null,
    @inDriverName varchar(64) = null
as
set nocount on

declare @theOrderAuditInfoFID bigint
if( isnull( @inChangedBySysUserID, 0 ) <= 0 )
begin
    set @inChangedBySysUserID = ( select SysUserId from SysUser where SysUser.FIRSTNAME = 'External' and SysUser.LASTNAME = 'Application' )
end

if( isnull( @inDriverName, '' ) = '' and @inDriverSysUserID > 0 )
begin
    set @inDriverName = (
        select dbo.FormatFirstNameLastName( SysUser.FirstName, SysUser.LastName )
        from SysUser
        where SysUser.SysUserID = @inDriverSysUserID
    )
end

if( isnull( @inUpdateSource, '' ) = '' )
begin
    set @inUpdateSource = 'Unspecified Van Line Download'
end

exec PrepOrderForAuditLog
    @inSysUserID = @inChangedBySysUserID,
    @inUpdateSource = @inUpdateSource,
    @outOrderAuditInfoFID = @theOrderAuditInfoFID output

update OrdersExtended set
    CurrentDriver = @inDriverName,
    OrderAuditInfoFID = @theOrderAuditInfoFID
from OrdersExtended
where OrdersExtended.OrderFID = @inOrderID
GO
GRANT EXECUTE ON  [dbo].[UpdateCurrentDriverName] TO [MssExec]
GO
Uses