Link to home
Start Free TrialLog in
Avatar of SNilsson
SNilssonFlag for Sweden

asked on

Insert, cursor, sp


I'm inserting info from the sp getfiledetails into a temp table as below:
______________________________________________
OPEN cur
FETCH NEXT FROM cur INTO @Filename
WHILE @@FETCH_STATUS = 0
BEGIN
     SET @Filename = @Directory + @Filename
     INSERT #FileInfo EXEC xp_getfiledetails @Filename
     FETCH NEXT FROM cur into @Filename
END
______________________________________________
This is working fine, however I want to add the info from the @Filename variable also into the #FileInfo table how can I do that ?
Avatar of Jay Toops
Jay Toops
Flag of United States of America image

alter table #filename add fname varchar(255)
update #filename
set fname=@filename
where fname is null
alter table #fileinfo add fname varchar(255)
update #filename
set fname=@filename
where fname is null
Avatar of SNilsson

ASKER


That will work for the first loop maybe, but only the first.
-- check to see if the field exists before adding
IF NOT EXISTS
   (SELECT c.* FROM syscolumns c   JOIN sysobjects o ON c.id = o.id
    WHERE o.name = '#fileinfo'  AND c.name = 'fname')
   BEGIN
      -- Field does not exist
      alter table #fileinfo add fname varchar(255)
   END

update #fileinfo
set fname=@filename
where fname is null

ASKER CERTIFIED SOLUTION
Avatar of OlegP
OlegP

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I used a identity column and then did an update on the column with the DOS filename in it, so points for OlegP for giving the idéa of using a identity column.