Latife
Latife

Reputation: 15

SQL procedure put today's date to the file name

I am creating a procedure and trying to put output file name with today's date. Whenever I run it, I want to see that date with MMDDYYYY format. I have 2 output file, so their name will be AD_MMDDYYY and the other one is IM_MMDDYYYY

    IF la_dtc_population.COUNT > 0
   THEN
       IF pv_file_type IN ('ID.&sysdate', 'AD.&sysdate' )

What it will be, this doesn't work? Thanks

Upvotes: 0

Views: 2812

Answers (1)

David R Tribble
David R Tribble

Reputation: 12204

This might not answer your question, but the following SQL will fill the variable @date with the current date in the format mmddyyyy, which you can then use to create the appropriate filenames:

declare @now    varchar(20) =
    convert(varchar(20), getdate(), 20);    -- Format 'yyyy-MM-dd hh:mm:ss'
declare @date   varchar(20) =
    substring(@now, 6, 2) + substring(@now, 9, 2) + substring(@now, 1, 4);

I think this should be pretty standard SQL (although I used MS-SQL/T-SQL to test it).

Upvotes: 1

Related Questions