0

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

Latife
  • 15
  • 5
  • Which [DBMS](https://en.wikipedia.org/wiki/DBMS) product are you using? "SQL" is just a query language, not the name of a specific database product. Please add the tag for the database product you are using `postgresql`, `oracle`, `db2`, `sql-server`, ... –  Mar 25 '19 at 19:09
  • Possible duplicate of [sql server convert date to string MM/DD/YYYY](https://stackoverflow.com/questions/11854775/sql-server-convert-date-to-string-mm-dd-yyyy) – TFD Mar 25 '19 at 19:47

1 Answers1

1

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).

David R Tribble
  • 11,918
  • 5
  • 42
  • 52