Solved

How to combine INSERT, EXEC master..getfiledetails, SELECT ?

Posted on 2003-12-10
6
842 Views
Last Modified: 2012-08-13
I'm newbie in SQL commands. Is possible to combine this commands?

INSERT ##filedetails
EXEC master..getfiledetails 'c:\filename.txt'
SELECT filename FROM ##filenametable

Command SELECT must be parameter of EXEC master..getfiledetails procedure and output I want to insert to ##filedetails table.

Like this: INSERT ##filedetails EXEC master..getfiledetails SELECT filename FROM ##filenametable

Thank you for response. Martin
0
Comment
Question by:martin_mmj
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 9910940
what is getfiledetails ??? it is not a system sp/
0
 

Author Comment

by:martin_mmj
ID: 9910959
Ohhh, sorry. Must be master..xp_getfiledetails.

Thanks. M.

0
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 9911012
Yes. you can execute lot of sql statements at ones. but I think before you run this SQL. You must create a temp table First.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:martin_mmj
ID: 9911084
Yes, the table ##filedetails was created first and the table ##filenametable contains a lot of path-filenames.

If I run script

INSERT ##filedetails EXEC master..xp_getfiledetails 'c:\pagefile.sys'

one row is OK inserted to the table ##filedetails. But I want run this commands for all rows in ##filenametable.

Can you help me? Thanks. M.
0
 
LVL 8

Accepted Solution

by:
Dishan Fernando earned 25 total points
ID: 9911135
write cursor..

DECLARE @Filename varchar(100)

DECLARE CURSOR cur
SELECT filename FROM ##filenametable

OPEN cur

FETCH NEXT FROM cur into @Filename

WHILE @@FETCH_STATUS = 0
BEGIN
      INSERT ##filedetails EXEC master..xp_getfiledetails @Filename
      FETCH NEXT FROM cur into @Filename
END

CLOSE cur
DEALLOCATE cur
0
 

Author Comment

by:martin_mmj
ID: 9911261
Thank you for idea. Now it works OK.

Martin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

861 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