I am having trouble working on a cursor function could someone check for me it the should work.
ALTER Function dbo.ZeroFill_ObjectNumber (@ObjectNumber char(42))
RETURNS Varchar(2000) AS
BEGIN
declare @stringvar as varchar(255)
declare cur CURSOR FOR select Objects.ObjectNumber
from Objects
where ObjectLevelID = '6'
and objectnumber like 'GR%'
and objectnumber not like 'GR[0-9][0-9][0-9][0-9]'
and objectnumber not like 'GR[0-9][0-9][0-9][0-9][.][0-9][0-9][0-9][0-9]%'
and objectnumber not like 'GR[0-9]'
--and Objects.ObjectId = ObjComponents.ObjectId
OPEN cur
set @stringvar = ''
fetch next from cur into @stringvar
While @@fetch_status = 0
BEGIN
IF @stringvar Like '%.[0-9][0-9]/%'
Begin
set @stringvar = substring(@stringvar,1,patindex('%.%',@stringvar)) + '00' +substring(@stringvar,patindex('%.%',@stringvar)+1 ,len(@stringvar))
End
Else If @stringvar Like '%.[0-9][0-9][0-9]/%'
Begin
set @stringvar = substring(@stringvar,1,patindex('%.%',@stringvar)) + '0' +substring(@stringvar,patindex('%.%',@stringvar)+1 ,len(@stringvar))
End
fetch next from cur into @Stringvar
END
CLOSE cur
DeAllocate cur
return @stringvar
END
as well I am have touble figuring out how to then set a update up to change the ObjectNumber in the objects table.
I hope you can help