June 23, 2005 at 1:27 pm
Hi all,
I am trying to create procedure that will separate field from concatinated fields. such as “21.test”. The “test” is really the Department, and the 21 is the Project.
How can i separate these from one field.
Help:
Thanks
June 23, 2005 at 1:31 pm
You want to correct the design and split that column?
Select Left(FieldName, charindex('.', FieldName, 1) - 1) as Project, Right (FieldName, LEN(FieldName) - charindex('.', FieldName, 1)) as Departement
June 23, 2005 at 1:35 pm
hi,
yes, currently they have the 21.test in one column and now they want to split them and put it in to separat such as 21 in project column and test in department column.
thanks
June 23, 2005 at 1:38 pm
Update YourTable SET Project = Left(FieldName, charindex('.', FieldName, 1) - 1), Departement = Right (FieldName, LEN(FieldName) - charindex('.', FieldName, 1))
You might wanna make sure that the project is numeric in all the rows to make sure this doesn't fail (using my previous select as a starting point)
June 23, 2005 at 2:37 pm
Hi,
not it's not numeric!! it's varchar!! how can i make change on to that!!
Thanks
June 23, 2005 at 3:41 pm
hi in
the last response which is update statement i says
Invalid length parameter passed to the substring function.
thanks
June 23, 2005 at 4:35 pm
It probabely means that there's no period in the field... maybe you could check it out with this query :
Select * from dbo.YourTable where charindex('.', YourField, 1) = 0
To correct the problem in the update you can use this technique where there's a len() -1
do ABS(LEN(something) - 1) and the error should go away... but that would also mean that the data is wrong.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply