-- create the tally table
SELECT TOP (30)
IDENTITY(INT,0,1) AS N
FROM Master.dbo.SysColumns sc1,
-- Add an index
ALTER TABLE #Tally
ADD CONSTRAINT PK_Tally_N2
PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100
-- strip the commas and keep the string horizontal
declare @datastring varchar(8000),
set @datastring = 'A,B,C,D,E,F,G,H,I,J,K'
set @datastring2 = ''
-- Why doesn't the select directly below return anything?
select @datastring2 = @datastring2 + substring(@datastring,N,1)
where n <=len(@datastring)
and substring(@datastring,N,1) <> ','
-- this one returns the data
select @datastring2 as CleanString
I'm putting together some materials to demonstrate some of the uses for tally tables (thanks Jeff :-) )
and stumbled across a curious issue with the query above that "stuffs" @datastring2.
It doesn't directly return any data (doesn't have to really) but I can't explain why and I was hoping someone could explain that to me.
This is not urgent in any way. I'm just trying to keep learning from you wonderful folks