[p]I can't quite remember writing this. I think I must have been trying to check out the process for submitting scripts for some reason, and grabbed something I had to hand. Apologies for the awful header, which explains very little. I hurriedly tried it out and to my surprise it seems to work.[/p]
[font="Courier New"]DECLARE @TabbedStuff VARCHAR(2000)
SELECT @TabbedStuff='
'+CHAR(9)+ 'SELECT @tabsize = COALESCE(@tabsize, 4)
'+CHAR(9)+ 'IF @string IS NULL RETURN NULL
'+CHAR(9)+ 'DECLARE @OriginalString VARCHAR(8000),
'+CHAR(9)+CHAR(9)+'@DetabbifiedString VARCHAR(8000), @Column INT, @Newline INT
'+CHAR(9)+ 'SELECT @OriginalString = @String, @DeTabbifiedString = '', @NewLine = 1,
'+CHAR(9)+CHAR(9)+'@Column = 1
'+CHAR(9)+'WHILE PATINDEX(''%['' + CHAR(9) + CHAR(10) + '']%'', @OriginalString) > 0'
SELECT dbo.expandTabs(@TabbedStuff,3)
[/font][p]The code comes from the Code Prettifier, of course, so if I extracted it properly, then I guess it works. I've updated the Prettifier since then but not this logic as it seems to work OK. Unfortunately, I haven't updated the version of the prettifier on http://extras.sqlservercentral.com/prettifier/default.aspx but I will as soon as I get a quiet week (nervous laugh)[/p]
Best wishes,
Phil Factor