Mille Bournes
From a SQLTeam freind, Thanks Duane
http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=9857
QA Needs to be set to text mode and font courier
SET NOCOUNT ON
DECLARE @InpString VARCHAR(4000)
DECLARE @CharCT INT
DECLARE @PrevY INT
DECLARE @CurrX INT
DECLARE @CurrY INT
DECLARE @InpRow VARCHAR(4000)
DECLARE @RowCT INT
SET @RowCT = 1
SET @InpString = '04040404080409041004110415041604170418042204230424042504'
SET @InpString = @InpString + '030503050405070512051405190521052605'
SET @InpString = @InpString + '030603060406070612061406190621062606'
SET @InpString = @InpString + '020702070407070712071407190721072607'
SET @InpString = @InpString + '020802080408070812081408190821082608'
SET @InpString = @InpString + '010901090409070912091409190921092609'
SET @InpString = @InpString + '011001100410071012101410191021102610'
SET @InpString = @InpString + '0011001101110211031104110511071112111411191121112611'
SET @InpString = @InpString + '04120412071212121412191221122612'
SET @InpString = @InpString + '04130413081309131013111315131613171318132213231324132513'
CREATE TABLE #Stuff(X INT, Y INT)
CREATE TABLE #BK(BID INT, B VARCHAR(4000))
SET @CharCT = 1
WHILE @CharCT < LEN(@InpString)
BEGIN
INSERT INTO #Stuff VALUES(CAST(SUBSTRING(@InpString, @CharCT, 2) as INT) + 1, SUBSTRING(@InpString, @CharCT + 2, 2))
SET @CharCT = @CharCT + 4
END
DECLARE BrettCur
CURSOR FOR
SELECT * FROM #Stuff
ORDER BY 2
SET @InpRow = ''
OPEN BrettCur
FETCH NEXT FROM BrettCur INTO @CurrX, @CurrY
SET @CharCT = 0
SET @PrevY = @CurrY
WHILE @@FETCH_STATUS = 0
BEGIN
IF @CurrY = @PrevY
BEGIN
WHILE @CharCT < @CurrX
BEGIN
SET @InpRow = @InpRow + ' '
SET @CharCT = @CharCT + 1
END
SET @InpRow = @InpRow + '@'
SET @CharCT = @CharCT + 1
END
ELSE
BEGIN
INSERT INTO #BK VALUES(@PrevY, @InpRow)
SET @CharCT = 0
SET @PrevY = @CurrY
SET @InpRow = ''
END
FETCH NEXT FROM BrettCur INTO @CurrX, @CurrY
END
CLOSE BrettCur
DEALLOCATE BrettCur
INSERT INTO #BK VALUES(99, @InpRow)
SELECT B
FROM #BK
ORDER BY BID
DROP TABLE #Stuff
DROP TABLE #BK