469,898 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Still need more help

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
Jul 31 '07 #1
0 677

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by MARTIN DAVIES | last post: by
34 posts views Thread by s c o t t | last post: by
13 posts views Thread by EggsAckley | last post: by
687 posts views Thread by cody | last post: by
46 posts views Thread by Kamilche | last post: by
8 posts views Thread by john | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.