how to increment a file extension

  • Can you please help me on how can i make the file names stay constant and that the extension be incremental ( name.R0001, name.R0002 etc.) the file extension value is stored in a SP.i need to get the extension value then add them together with the file name eg: file name + extension value

  • Hi,

    declare @filename nvarchar(10), @num int, @num1 int, @extension nvarchar(15)

    set @filename = 'abc.txt1'

    set @filename = rtrim(@filename)

    set @num = len(@filename) - ((charindex('.',@filename)) + 1)

    set @extension = substring(@filename, ((charindex('.',@filename)) + 1), @num )

    set @num1 = cast( substring(@filename,len(@filename), len(@filename)) as int)

    while( @num1 < = 10 )

    begin

    set @num1 = @num1 + 1

    set @filename = 'abc.' + @extension + cast(@num1 as nvarchar(10))

    print @filename

    end

    Try this and tell me if you are satisfied with this solution or not

    Best Regards,

    Preetha SG

  • Hi Preetha

    which component can i use for the code u just send me

    regards

    Nosi

  • Hi,

    I used this in SQL Server 2005. In which, you want to do this?

    Best Regards,

    Preetha SG

  • hi,

    You can use the preetha script in the Script task or the file system task.Nice script preetha:)

    cheers mate

    vijay

  • Hi Preetha

    Thanx a lot it work 😉

    regards

    Nosi

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply