Sql Server Back Up - sql-server

I'm using the below to backup a db from a SQL job. Can someone tell me how to add the current date to the output filename? Preferably in YYYYMMDD format.

Related

Parse datetime in SQL Server with Time Zone information

I have a datetime taken from my system in the following format inside an Excel table: "2021-11-02 09:54:52 EDT". SQL Server can't parse the timezone.
Is there a way for SQL Server to parse this timezone or do I need to remove it from the CSV, or should I parse it in Excel?

Store date in dd-mm-yyyy format or dd.mm.yyyy format in SQL Server (AWS RDS Distribution)

I'm migrating data from DB2 for Z/os (Mainframe) to RDS distribution of SQL Server.
In the mainframe, the date is stored in EURO format which is DD.MM.YYYY, when I migrate the data to SQL Server, the data is stored in SQL Server in YYYY-MM-DD ISO format.
All of my application program expects the date to be in DD.YY.MMMM format. I know I can use convert function at application programs to format the date to convert to EURO format. There are thousands of programs which would require change if I take that route.
Is there a way I can enforce SQL Server to store the date in DD.MM.YYYY or DD/MM/YYYY format ?
I already tried changing the Default Language of SQL server to "British English" it doesn't seem to be of any help. When I issue "DBCC USEROPTIONS" it shows Language as "BRITISH" and Date as 'dmy' but still when application program retrieves the date it's in yyyy-mm-dd format only.
My application program connects to SQL Server via ODBC driver and I have tried changing the OS Date from Control panel as well of dd/mm/yyyy format. Any advice on this issue will be of great help.
Thanks in advance!
I already tried changing the Default Language of SQL server to "British English" it doesn't seem to be of any help. When I issue "DBCC USEROPTIONS" it shows Language as "BRITISH" and Date as 'dmy' but still when application program retrieves the date it's in yyyy-mm-dd format only.
If you want to guarantee that that dates are returned as dd.mm.yyyy, then you can convert them to a string:
select convert(char(10), datecol, 104)
In SQL Server, you can handle this by using views or adding computed columns to the tables:
alter table d add datecol_ddmmyyyy as ( convert(char(10), datecol, 104) );
Otherwise, the application should be able to ingest SQL Server dates in the native format. This is only relevant if they are being converted to strings.

How to automate SQL Server query and automatically put the results in an Excel file

Currently have a lot of queries to run on the first of the month and on Mondays of every week in Microsoft SQL Server. Does anyone know how I could automate the
queries to run on their own and then put the results in an Excel file?
the easiest thing is probably to set up reports in Report Server (SSRS) to execute your SQL and render them into the appropriate format. You can then schedule the reports to run on whatever days you want and email the results exported into an Excel file.

Oracle to SQL server Migration Date Format changes

I Used SELECT TO_CHAR(sysDate,'dy') FROM DUAL In oracle and I want to get the same output in SQL Server. I tried several ways and I want to know the date style value for this format.
CONVERT(VARCHAR(max),'2017-03-06T00:00:00.000',<DateStyle>)

SSIS converts .csv date field to incorrect format on production SQL server

I am using SSIS 2005 to read data off a .csv file into a SQL Server 2005 Database. I am using a Flat File connection manager for the .csv and an OLEDB Connection Manager for the resulting rows.
The .csv file contains a field which is a date in UK format (dd/mm/yyyy), which may be written, say, 7/3/2011 for 7th March 2011. This column is then mapped onto the equivalent datetime field in the SQL Server database.
The problem I am facing is that, while everything works fine on the development machine, when used on the production environment, the dates get changed to US (mm/dd/yyyy) format (if valid), when they are inserted into SQL Server. Is there some place where the desired Region/Format (in this case UK) for the destination datetime field can be specified, maybe somewhere in the package or some setting on the production server itself?
Thanks in advance,
Tim
You can set the locale in the Flat File Connection Manager Editor or LocaleID in the Properties box for the connection (same thing). Setting it to "English (United Kingdom)" will interpret the dates correctly, because SSIS uses the locale in the package or data flow, not the OS locale.
Note that you have to set the format at the source, not the destination: datetime is a binary format in MSSQL so dates aren't stored internally in a locale-specific format anyway.

Resources