Solved

Insert, cursor, sp

Posted on 2004-09-13
6
1,745 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 250 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now