sql query to display a trailer record at the end in txt file (using batch file)

  • Sergiy (10/12/2016)


    To do it all in one query you may use GROUP BY ... WITH ROLLUP.

    In the row with GROUPING(Column1) = 1 you concatenate COUNT(*) , GETDATE() and whatever else you need to put there (after converting them all into varchars, of course.

    Spot on, Sergiy.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Okay! I will try it out.

    Thanks.

  • Hi ,

    I have this batch file as below. I need to update this to get the date without setting it as I have done in the second line of my code below.

    I want it to display automatically when I run this batch file every time. The date should be in yyyymmdd format.

    I tried lot of options with date parameters but couldn't get this right.

    Can you please help me with this..

    *** Batch file ********************************************

    set naic=1211610

    set filedatetime=18/10/2016 11:03

    set date=%filedatetime:~6,4%%filedatetime:~3,2%%filedatetime:~0,2%

    set filename=tnvin_%date%%naic%.txt

    set tnpath=C:\tnvintrailerSQLCMD -S SQLSANDBOX -E -Q "[SouthernTrust].[dbo].[P_tntr] "

    bcp [St].[dbo].[TmpTNVINTRInfo] out "%tnpath%%filename%" -c -T -S SQLSANDBOX

    SQLCMD -S SQLSANDBOX -E -Q "DROP TABLE [St].[dbo].[TmpTNVINTRInfo]"

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply