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 1085799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:44:03+00:00 2026-05-16T22:44:03+00:00

I have a pretty simple question (and these are typically the ones I spend

  • 0

I have a pretty simple question (and these are typically the ones I spend most of my time tearing my hair out about). I am using a batch file to execute all the .sql queries that are in the same directory as the batch, and to save all their results to various .csv file.

Here is my code:

@echo off

REM Check that all parameters are present
@IF "%1"=="" goto error
@IF "%2"=="" goto error
@IF "%3"=="" goto error
@IF "%4"=="" goto error

REM For every *.sql file in this folder "." and all its subfolders (/R), do the following: 
@for /R "." %%F in (*.sql) do (
REM Print the command to be executed:
@echo Database : @SqlCmd -S %1 -U %2 -P %3 -d %4 -I -l60 -i "%%F" -o "%%F.output.csv"  -h-1 -s"," -w 1000 -W
REM Execute the command:
@SqlCmd -S %1 -U %2 -P %3 -d %4 -I -l60 -i "%%F" -o "%%F.output.csv" -h-1 -s"," -w 1000 -W
)

goto :EOF

:error

@echo Incorrect syntax : 
@echo     extract.cmd [servername] [user id] [password] [databasename]
@echo   
@pause

goto :EOF

As a test, I run the following query:

select top(10) [name] from sysobjects 

which outputs:

sysrscols
sysrowsets
sysallocunits
sysfiles1
syspriorities
sysfgfrag
sysphfg
sysprufiles
sysftinds
sysowners

(10 rows affected)

This works fine, except for two things. Firstly, I need to have the column headers output as well. So I remove the “-h -1” parameter, which then gives:

name
----
sysrscols
sysrowsets
sysallocunits
sysfiles1
syspriorities
sysfgfrag
sysphfg
sysprufiles
sysftinds
sysowners

(10 rows affected)

which is great except for the fact that I don’t want the horizontal rule “——” between the heading and the first row of data.

Also, I don’t want the “(10 rows affected)” line to be output.

Does someone know how I could achieve this?

Thanks
Karl

  • 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-05-16T22:44:03+00:00Added an answer on May 16, 2026 at 10:44 pm

    try this:

    SET NOCOUNT ON;
    SELECT
        [Name]
        FROM (SELECT TOP(10)
                  2 AS SortBy, [name]
                  FROM sysobjects 
              UNION
              SELECT 1, 'Name'
             ) dt
        ORDER BY [Name]
    

    OUTPUT FROM SSMS:

    Name
    ----------------------------------------------
    Name
    sysallocunits
    sysfiles1
    sysftinds
    syshobtcolumns
    syshobts
    sysowners
    sysprivs
    sysrowsetcolumns
    sysrowsets
    sysserefs
    

    leave the “-h -1” parameter and the column headings will be removed, but the “Name” row will still appear in the result set first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple question this time around. I have an application that communicates with another
Pretty simple question: When i have a persistable object, it usually has a property
I have a pretty simple question, but with an answer that I am unable
The question is pretty simple actually. I have a module in my system containing
my question is pretty simple, I think. And it's more about math than coding.
Pretty simple question, I have a webpage that is used exclusively on iPads. I've
Should be pretty simple: I have an InputStream where I want to peek at
Pretty simple scenario. I have a web service that receives a byte array that
I am pretty new to php, but I am learning! I have a simple
I have a pretty standard table set-up in a current application using the .NET

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.