I need to return two fields from a database concatenated as \'field1-field2\'. The second field is an int, but needs to be returned as a fixed length of 5 with leading 0\'s. T
If you can afford/want to have a function in your database you could use something like:
CREATE FUNCTION LEFTPAD (@SourceString VARCHAR(MAX), @FinalLength INT, @PadChar CHAR(1)) RETURNS VARCHAR(MAX) AS BEGIN RETURN (SELECT Replicate(@PadChar, @FinalLength - Len(@SourceString)) + @SourceString) END