Using TSql to bulk insert a text file into a Sql Server 2012 transactional database.
Dates within text file are in the format YYYYMMDD.
I initially import all of data with data type of varchar into temporary table and then import into production table with a datetime2 data type.
Displayed below - I am testing the portion of the sql script that I will use to import the data from the temporary table into the production table.
Issue: I am not able to filter the data by Sale_Date.
For example, I want to import the data with a Sale_Date from January 1, 2016 to December 31, 2016 into Table "Sales_2016"
Using the sql script below, I receive records with a Sale_Dates of 1/01/2016, 1/01/2015, 1/2/2016, 1/5/2015...
It appears that the records are not being filtered properly.
Any insight as to what revisions I need to make to effectively filter the desired records?
Dates within text file are in the format YYYYMMDD.
I initially import all of data with data type of varchar into temporary table and then import into production table with a datetime2 data type.
Displayed below - I am testing the portion of the sql script that I will use to import the data from the temporary table into the production table.
Issue: I am not able to filter the data by Sale_Date.
For example, I want to import the data with a Sale_Date from January 1, 2016 to December 31, 2016 into Table "Sales_2016"
Using the sql script below, I receive records with a Sale_Dates of 1/01/2016, 1/01/2015, 1/2/2016, 1/5/2015...
It appears that the records are not being filtered properly.
Any insight as to what revisions I need to make to effectively filter the desired records?
Code:
Select
Case
When len(rtrim(ltrim([Sale_Date]) < > 8 then null
When rtrim(ltrim([Sale_Date])) not like '[0-9][0-9][0-9][0-9][0-9][0-9][0-3][0-9]' then null
When isdate(rtrim(ltrim([Sale_Date]))) = 1 then convert(varchar(10), cast([Sale_Date] as datetime2),101)
else [Sale_Date]
from #TempTable
Where convert (varchar(10),cast ([Sale_Date] as datetime2),101) between '01/01/2016' and '12/31/2016'