Solved

Insert, cursor, sp

Posted on 2004-09-13
6
1,777 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

689 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