Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:46:22+00:00 2026-06-18T07:46:22+00:00

What I have I am currently inserting all the SQL files from the current

  • 0

What I have

I am currently inserting all the SQL files from the current directory in a temporary table :

create table #tmpSQLFiles(SQLFileName varchar(max))  
set @SqlStatement = 'master.dbo.xp_cmdshell ''dir /b "' + @DirPath + '*.sql"'''

insert into #tmpSQLFiles
execute (@SqlStatement)

This works well.

What I want

Now I want the table to have an extra varchar column in which I can store a certain desired string :

create table #tmpSQLFiles(SQLFileName varchar(max), MyString varchar(max))
set @SqlStatement = 'master.dbo.xp_cmdshell ''dir /b "' + @DirPath+ '*.sql"'''

What I have tried

How can I do the insert? I have tried :

insert into #tmpSQLFiles (SQLFileName, MyString) values (execute (@SqlStatement), 'aa')

or :

declare @ExecutedStmt varchar(max)
set @ExecutedStmt = execute (@SqlStatement)
-- But the above line is not correct.

Any of these 2 would work for me. I don’t want to insert and update afterwards the second column.

Any ideas on how I can achieve this? Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:46:23+00:00Added an answer on June 18, 2026 at 7:46 am

    Try using a table variable as an intermediary – not the prettiest, but does the job:

    create table #tmpSQLFiles(SQLFileName varchar(max), MyString varchar(max))
    set @SqlStatement = 'master.dbo.xp_cmdshell ''dir /b "' + @DirPath + '*.pdf"'''
    
    DECLARE @TempOutpt TABLE ([output] varchar(500))
    insert into @TempOutpt ([output])
    execute (@SqlStatement)
    
    insert into #tmpSQLFiles (SQLFileName, MyString)
    select [output], 'my string here' from @TempOutpt
    
    select * from #tmpSQLFiles
    

    If you weren’t using an extended stored procedure (xp_cmdshell), you might have been able to use OPENROWSET to execute the SP:

    SELECT *fields* 
    FROM OPENROWSET('SQLNCLI', 
                    'Server=*your_server*;Trusted_Connection=yes;Database=*your_database*', 
                    'exec *stored_procedure* *parameters*')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this procedure for inserting rows in tables(sql server 2005) CREATE PROCEDURE ans_insert
Into : Currently i have scraped all the data into one PostgreSQL 'Bigtable' table(there
I erroneously delete all the rows from a MS SQL 2000 table that is
I have a web app that currently is inserting x (between 1 + 40)
I have currently in a table about 90k rows. And it's will grow up
I have currently got imagepaths stored within the database and image files stored in
I currently have a dropdown box which enters an integer into a table. It's
I currently have a table that is 17 columns wide and has 30 records.
anyone know how to optimize SQL query for inserting data from select statement and
I am currently creating a website and have some javascript that works in all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.