?
Solved

Insert, cursor, sp

Posted on 2004-09-13
6
Medium Priority
?
1,786 Views
Last Modified: 2008-01-09

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 ?
0
Comment
Question by:SNilsson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12043927
alter table #filename add fname varchar(255)
update #filename
set fname=@filename
where fname is null
0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12043943
alter table #fileinfo add fname varchar(255)
update #filename
set fname=@filename
where fname is null
0
 
LVL 8

Author Comment

by:SNilsson
ID: 12043974

That will work for the first loop maybe, but only the first.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 10

Expert Comment

by:Jay Toops
ID: 12043996
-- 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

0
 
LVL 6

Accepted Solution

by:
OlegP earned 750 total points
ID: 12044037
To #FileInfo  add  the following  IDR INT IDENTITY(1,1), DR varchar(250),FN varchar(500)


change
 INSERT #FileInfo EXEC xp_getfiledetails @Filename
to
 INSERT #FileInfo ([alternate name],.....,[Attributes]) --all list of fields
EXEC xp_getfiledetails @Filename
UPDATE  #FileInfo
SET DR = @Directory ,FN=@Filename
WHERE IDR=@@IDENTITY
0
 
LVL 8

Author Comment

by:SNilsson
ID: 12160013

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.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question