MrsMope987
Programmer
- Sep 27, 2007
- 23
Hello,
I have a field that has 13 values in it separated by a semi-colon. Each value = a month, the 13th is for year-end adjustments. The table housing this field is stored in a PROGRESS database, I'm using the following SQL function to split these values into unique rows. I have SQL 2005;
THis all works great, but I want to add an additonal column to my results table called 'Mnth' which corresponds to the position of the value in the field. IE: first value=1 in Mnth, second Value= 2in mnth. How do I do this?
Finally I'd like to take this function and make it so I can permanetly store this table in SQL because once I get this done I need to add a few more things to the data (Acct Descrp etc) and then use SQL Reporting to design a report.
I have a field that has 13 values in it separated by a semi-colon. Each value = a month, the 13th is for year-end adjustments. The table housing this field is stored in a PROGRESS database, I'm using the following SQL function to split these values into unique rows. I have SQL 2005;
Code:
ALTER FUNCTION [dbo].[ParseValues]
(@String varchar(8000),
@Delimiter char(1)
)
RETURNS @RESULTS TABLE
(ID int identity(1,1),
Val varchar(1000)
)
AS
BEGIN
DECLARE @Value varchar(100)
WHILE @String is not null
BEGIN
SELECT @Value=CASE WHEN CHARINDEX(@Delimiter,@String) >0
THEN LEFT(@String,CHARINDEX(@Delimiter,@String)-1)
ELSE @String
END,
@String=CASE WHEN CHARINDEX(@Delimiter,@String) >0
THEN SUBSTRING(@String,CHARINDEX(@Delimiter,@String)+1,LEN(@String))
ELSE NULL
END
INSERT INTO @RESULTS (Val)
SELECT @Value
END
RETURN
END
THis all works great, but I want to add an additonal column to my results table called 'Mnth' which corresponds to the position of the value in the field. IE: first value=1 in Mnth, second Value= 2in mnth. How do I do this?
Finally I'd like to take this function and make it so I can permanetly store this table in SQL because once I get this done I need to add a few more things to the data (Acct Descrp etc) and then use SQL Reporting to design a report.