Solved

Insert, cursor, sp

Posted on 2004-09-13
6
1,750 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

910 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

17 Experts available now in Live!

Get 1:1 Help Now