Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 String functions

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-10-26 : 16:24:59
We have a problem with the data filenames, just the first part of teh filename which is 1654 to be replaced with teh appropriate number.
D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf

I have almost 20,000 rows to be modified just the filename first part.

The have the filepath : "D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf"

how can i replace the part 1654 with @Docid parameters value.

Thank you very much for the help.

mfemenel
Professor Frink

1421 Posts

Posted - 2009-10-26 : 16:43:47
well I'm going on the assumption you have 1654 all the time in your string. Use the replace function to fix it up based on your @DOCID parameter. here's an example.

declare @myval varchar(10)
set @myval='\1111.'
select replace('D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf','\1654.',@myval)

Mike
"oh, that monkey is going to pay"
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-10-26 : 16:47:34
1654 is just an example it could be anything between "\" and "."


Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-10-26 : 16:51:21
is this 'D:\ProjectImages\DUS\DM\' always constant in the database or does that change up too?

<><><><><><><><><><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-10-28 : 09:50:31
I am sorry responding late.
yes this part is same for this job: 'D:\ProjectImages\DUS\DM\'


Thank you very much for the helpful info.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-10-28 : 10:04:18
[code]declare @d varchar(1000)
select @d = 'D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf'
select @d = replace(@d,substring(@d,(charindex('DM\',@d) + 3),charindex('.',@d) - (charindex('DM\',@d) + 3)),'urvalue')
select @d[/code]
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-28 : 10:06:24
[code]
declare @sample table
(
filepath varchar(50)
)

insert into @sample select 'D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf'
insert into @sample select 'D:\ProjectImages\DUS\DM\.4836-C-1013.pdf'
insert into @sample select 'D:\ProjectImages\DUS\DM\1234567.4836-C-1013.pdf'

declare @docid varchar(10)

select @docid = '8888'

select filepath, slash, dot, new_filepath = stuff(filepath, slash + 1, dot - slash -1, @docid)
from
(
select filepath, slash, dot = charindex('.', filepath, slash + 1)
from
(
select filepath, slash = len(filepath) - charindex('\', reverse(filepath)) + 1
from @sample
) s
) s

/*
filepath slash dot new_filepath
-------------------------------------------------- ----------- ----------- --------------------------------------------
D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf 24 29 D:\ProjectImages\DUS\DM\8888.4836-C-1013.pdf
D:\ProjectImages\DUS\DM\.4836-C-1013.pdf 24 25 D:\ProjectImages\DUS\DM\8888.4836-C-1013.pdf
D:\ProjectImages\DUS\DM\1234567.4836-C-1013.pdf 24 32 D:\ProjectImages\DUS\DM\8888.4836-C-1013.pdf

(3 row(s) affected)
*/
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-28 : 10:10:04
[code]
declare @myval varchar(10)
set @myval='\1111.'
select replace(file_path,substring(stuff(file_path,1,24,''),1,charindex('.',stuff(file_path,1,24,''))),@myval) from
(
select 'D:\ProjectImages\DUS\DM\1654.4836-C-1013.pdf' as file_path union all
select 'D:\ProjectImages\DUS\DM\902873.78456-C-15013.pdf'
) as t
[/code]

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-28 : 10:10:48




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-10-28 : 10:18:22
Wonderful.
Thank you very much for the help Vijay.
Go to Top of Page
   

- Advertisement -