I am trying to bulk import a data csv file into a database table. One of the columns in the csv file is a Date column. Unfortunately, the dates in this column are in different formats, namely, some are in YYYYMMDD and some are YYYY/MM/DD. They are also stored as type string in the csv.
I am trying to set the Date column in the table to be a calculated column, such that, when I import the csv file, the dates in the date column in the csv, are converted into a consistent format, i.e. YYYYMMDD.
Is this possible?
How can I set the calculated table column to do this?
I have tried the below, but am getting an error, as I cannot reference the same column in a calculated column (doh!).
[Date] AS TRY_CONVERT(DATE, [Date])
Related
I am trying to create a calendar using Power Query functions and for that I used below syntax in blank query:
Source= Duration.TotalDays(DateTime.LocalNow() - #datetime(2014,01,01,00,00,00)) * 24
Date= List.DateTimes(#datetime(2014,01,01,00,00,00), Source ,#duration(0,1,0,0))
Then I convert to a table and apply query.
Connect dimension date table to date column in fact table.
The error occurs when I’m trying to mark table as date table:
‘The date column can only gave one timestamp per day. The date column
can’t have gaps in dates’
What I have done wrong?
As the error message says:
The date column can only have one timestamp per day.
While you are trying to add 24, one for each hour. See the requirements for setting a table as a date table:
if it is a Date/Time data type, it has the same timestamp across each value
i.e. you can have only one value for each date, and if it is not a date, but datetime value, all time values should be the same.
I have DB with tables having datetime columns.
Can I add wrapper over those dateTime columns which I can activate/deactivate as per my need, so that all date time converted to a specific Timezone before retrieval.
e.g. I have a Table ABC with column ExpDate having value '12-10-2019 2:30'
When I execute
select * from ExpDate
then it will result
'12-09-2019 19:30' (after converting it from UTC to PST(UTC-7))
I want this solution be generic so that it get implemented for all dataTime column in all tables.
really struggling to convert the below date format 10.11.2013 in the format
of the system date.
I have a request to compare column data with the system date.
In the column the date is storing as DD.MM.YYYY
Or we need to convert system date (getdate()) to the date values stored in the database table.
Thanks in Advance
Regards,
Dev
try this:
convert system date (getdate()) to the date values stored in the
database table.
Gives formats as DD.MM.YYYY
select CONVERT( CHAR(10),GETDATE(),104) -- outputs 11.09.2014
with Your Column
select CONVERT( CHAR(10),MyColumn,104)
hi i am trying to update my tables consisting of dates i am encountering errors due to white spaces the date fields was given a varchar type by the pass programmer i want to convert my dates to this format mm/dd/yyyy but it seems the date fields are littered with this type of date APRIL 8, 2014 the question is how would i know that the date being updated are in this format sample APRIL 8, 2014? before updating it to proper format e.g mm/dd/yyyy
i have tried this SELECT convert(datetime, date_field, 101) but still it gives error
any suggestions?
The date and time datatypes in SQL Server do not have any implicit format. They are stored in an internal representation. The formatting is only applied when they are presented to a user on-screen or in a report etc. To store dates in a varchar() column was a mistake by the previous programmer which you should not repeat. Add a new column to your table of type date (http://msdn.microsoft.com/en-us/library/bb630352.aspx). Copy values from the current varchar to this new column, converting as you go. Both these statements work
select CONVERT(date, 'APRIL 8, 2014')
select CONVERT(date, '04/08/2014')
To be sure these are the only combinations you should do some analysis on the current values using regular expressions (outside of SQL) or SUBSTRING() (inside SQL).
Drop the old varchar and rename the new date column. You may have to drop and re-create constraints, indexes and foreign keys etc.
When passing these values back to the application keep them in date format. Let the user interface or reporting application format the date however it needs to.
I have a date column in the table which gets values from csv file. Right now if the date value is null, 1900/01/01 is getting inserted. How can I change it to empty string?
Thanks
In you CSV file select the column and change its type to simple text and then try to import the data.