• thanks again gsquared.

    really grateful of your help, and especially since the code is getting alot shorter.

    ran the script, but getting the SUBSTRING error again.

    just did some reading up on this error, and found this:

    Causes:

    This error is caused by passing a negative value to the length parameter of the SUBSTRING, LEFT and RIGHT string functions. This usually occurs in conjunction with the CHARINDEX function wherein the character being searched for in a string is not found and 1 is subtracted from the result of the CHARINDEX function.

    LEFT(@String, CHARINDEX(' ', @String) - 1)

    If the character is not found in a string, a space in this example, the CHARINDEX function will return a value of 0. Subtracting 1 to this will become -1 and using this as the length parameter in the SUBSTRING or LEFT functions will result to this error.