Quite often I need to cut off the first (or last) few characters of a string. To do just that I created two functions LSTR() and RSTR().
Syntax: LSTR( @stringtocut, @length )
Note: @stringtocut is trimmed in the function
When @length is equal or larger than zero, this function performs the same as LEFT( LTRIM(RTRIM(@stringtocut)), @length ).
When @length is smaller than zero, it returns LTRIM(RTRIM(@stringtocut)) minus the right @length characters.
Examples:
SET @ret = LSTR(' abcdef ',4) -> @ret = 'abcd'
SET @ret = LSTR(' abcdef ',0) -> @ret = ''
SET @ret = LSTR(' abcdef ',-4) -> @ret = 'ab'
SET @ret = LSTR(' abcdef ',9) -> @ret = 'abcdef'
SET @ret = LSTR(' abcdef ',-9) -> @ret = ''
Syntax: RSTR( @stringtocut, @length )
Examples:
SET @ret = RSTR(' abcdef ',4) -> @ret = 'cdef'
SET @ret = RSTR(' abcdef ',0) -> @ret = ''
SET @ret = RSTR(' abcdef ',-4) -> @ret = 'ef'
SET @ret = RSTR(' abcdef ',9) -> @ret = 'abcdef'
SET @ret = RSTR(' abcdef ',-9) -> @ret = ''
Write Reports from SQL to Disk (Even HTML!)
Ever need to write reports out to a folder? I have found that creating output files are SA-WEET! (and easy too) The sample script uses BCP to create an HTML file.This process works well for reports that need to be generated nightly and take too long to run in real time. Use an SMTP mail […]
2002-04-18
4,315 reads