Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-12-10
6
Medium Priority
?
852 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
[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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

636 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