Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using variable x as filename and incrementing value

Status
Not open for further replies.

lasd

Programmer
Jan 14, 2005
48
0
0
IE
Hi
I really hope someone can help. I am copying over files. I want to change the name of the file being copied over. I want the first one to start at 100,000 and increment from there.
for eg.
copy 1232.tif(source file) as 100000.tif and the second one to be 100001.tif and so on.
here is the code i have attempted to write.. i know its not correct but not sure what else to do with it.

select 'copy' ||trim(components.path)|| ' ' || x=100000, while x<150000, x=x + 1;
from docsadm.components

Just thinking that its only the name i want to change i want to keep the extension of the filename.
Please if someone can help i would be so grateful.
kindest regards

Lasd
 
It seems like you want to extract a value (the file name) from a table called docsadm.components and then build a script to create a copy File statement that would run under a dos prompt. Where docsadm is the name of the tables owner.

Is that correct?
 
yep this is correct. What i want to do is extract the value of components.path(this is a file name with a file extension)from the docsadm.component table, and change the name of components.path to 100000.tif, 100001.tif, 100002.tif etc........
my copy file statement that is being run under a dos prompt is working and copying the files over its just the renaming of the file where the problem lies.
thanks so much
 
Ok 2 step process..

step 1 build a temptable (in this case a table variable) with autonumber field (for incrementing the table number)

Pump the data you need into it and then do a select building the copy statemnt from the temp table

1.
Declare @t table (c1 int identity (100000,1),filename varchar(2000))
insert into @t (filename)
select components.path from components

2.
Select 'copy ' + filename + ' c:\newpath\' + cast(c1 as varchar(300)) + '.tif' from @t

then cut and paste your results..

Rob

 
Oh.. I should stress that the steps need to be run together..

ie in qa..
Code:
Declare @t table (c1 int identity (100000,1),filename varchar(2000))
insert into @t (filename)
select components.path from docsadm.components
Select 'copy ' + filename + ' c:\newpath\' + cast(c1 as varchar(300)) + '.tif' from @t

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top