[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2003-12-10
6
Medium Priority
?
854 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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 …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

830 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