Home Forums SQL Server 2008 SQL Server 2008 - General Urgent please help--Append Date(yyyymmdd format) to filename (Example: tnvin_20161019.txt) RE: Urgent please help--Append Date(yyyymmdd format) to filename (Example: tnvin_20161019.txt)

  • Thank You,

    I will also try it out.

    But I tried this .. and got the output.

    **********************************************************************************

    set naic=1261110

    set tnpath=C:\tnvintrailerset year=%date:~-4,4%

    echo year=%year%

    set month=%date:~-10,2%

    if "%month:~0,1%" == " " set month=0%month:~1,1%

    echo month=%month%

    set day=%date:~-7,2%

    if "%day:~0,1%" == " " set day=0%day:~1,1%

    echo day=%day%

    set datetime=%year%%month%%day%

    echo datetimef=%datetimef%

    SQLCMD -S SQLSANDBOX -E -Q "[St].[dbo].[P_tntr] "

    bcp [St].[dbo].[TmpTNVINTRInfo] out "%tnpath%tnvin_%datetime%%naic%.txt" -c -T -S SQLSANDBOX

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

    ****************************************************************************************