!**********************************************************************
!* *
!* MODULE: TDALIAS.SQC *
!* AUTHOR: TONY DELIA. *
!* DATE: 08/08/96. *
!* SYSTEM: TD SQR UTILITY SERIES. *
!* DESC: SQL STRING ALIAS REPLACEMENT. *
!* NOTE: THE EXAMPLE SHOWN BELOW REUSES THE PEOPLESOFT *
!* STANDARD PAY CALENDAR SELECTION SQL STRING FOR *
!* SUBSEQUENT SQL SELECTION IN THE PROGRAM. THIS IS *
!* USEFUL WHEN PROCESSING MULTIPLE SQL STATEMENTS *
!* (SELECT, UPDATE, DELETE, ... ) THAT REQUIRE THE *
!* IDENTICLE SELECTION CRITERIA. SIMPLY REPLACE THE *
!* ALIAS TO THAT OF YOUR TABLE. *
!* *
!**********************************************************************
!* *
!* USAGE: do Alias-SQL('A.', 'pc.', $SlctCalendar, $newSQL) *
!* . *
!* . *
!* #Include 'tdalias.sqc' *
!* *
!**********************************************************************
!* *
!* SAMPLE: begin-SQL *
!* update ps_pay_calendar pc *
!* set pc.gl_interface_run = 'Y' *
!* where [$newSQL] *
!* end-SQL *
!* *
!**********************************************************************
!* *
!* PARMS: $oldALIAS => Old Alias in SQL String *
!* $newALIAS => New Alias in SQL String *
!* $oldSQL => SQL String to convert *
!* *
!* RETURNS: $newSQL => New SQL String (converted) *
!* *
!**********************************************************************
!* *
!* LEGAL: CONFIDENTIALITY INFORMATION. *
!* *
!* This module is the original work of Tony DeLia. It *
!* can be considered ShareWare under the following *
!* conditions. *
!* *
!* A - The author's name (Tony DeLia) remains on any *
!* and all versions of this module. *
!* B - Any modifications must be clearly identified. *
!* C - A "vanilla" copy of this module must be kept *
!* alongside any revised versions. *
!* *
!**********************************************************************
!* *
!* WEBSITE: http://www.sqrtools.com *
!* *
!* Questions/Comments: tdelia@erols.com *
!* *
!**********************************************************************
begin-procedure Alias-SQL($oldALIAS, $newALIAS, $oldSQL, :$newSQL)
let $newSQL = ''
let #pos-a = 1
let #pos-b = 0
while #pos-b < length($oldSQL)
let #pos-b = instr($oldSQL, $oldALIAS, #pos-a)
if #pos-b = 0
let #pos-b = length($oldSQL) + 1
end-if
if #pos-a < #pos-b
let $newSQL = $newSQL ||
substr($oldSQL, #pos-a, #pos-b - #pos-a)
end-if
if #pos-b < length($oldSQL)
let $newSQL = $newSQL || $newALIAS
let #pos-a = #pos-b + length($oldALIAS)
end-if
end-while
display ' '
display 'Alias SQL Change - TDALIAS.SQC'
display ' '
display 'Old SQL: ' noline
display $oldSQL
display 'New SQL: ' noline
display $newSQL
display ' '
end-procedure
!**********************************************************************
!* End of Program *
!**********************************************************************
|