I’m trying to filter between two DateTimes allowing null values too
I’m using OdbcDataAdapter
objCon = new OdbcConnection(connStr05); objDA = new OdbcDataAdapter(query, objCon);
The connection is working fine because I use it for another select queries.
And I’m filling a datatable with that info
DataTable objDTfinal = new DataTable(); objDA.Fill(objDTfinal);
I’ve tested different queries…
This one works (don’t crash when start filling) but it crashes showing this error: Year, Month, and Day parameters describe an un-representable DateTime Exception
"SELECT * FROM DBName.PUB.gvehicu where (( "GVVE-fecmat" BETWEEN '1753-01-01' AND '2500-12-31' or ( "GVVE-fecmat" IS NULL )) and (( "GVVE-finiga" BETWEEN '1753-01-01' AND '2500-12-31') OR ( "GVVE-finiga" IS NULL )))"
The same query without null condition get half of the results but its working and filling it all fine.
My boss told me that when he works with dates, he uses Convert(DATETIME, value) so I tried this way too But this query automatically throws an error that cannot find the column DATETIME
"SELECT * FROM DBname.PUB.gvehicu where (( "GVVE-fecmat" BETWEEN CONVERT(DATETIME,'1753-01-01') AND CONVERT(DATETIME,'2500-12-31')) or ( "GVVE-fecmat" IS NULL )) and (( "GVVE-finiga" BETWEEN CONVERT(DATETIME,'1753-01-01') AND CONVERT(DATETIME,'2500-12-31')) OR ( "GVVE-finiga" IS NULL ))"
System.Data.Odbc.OdbcException: 'ERROR [42S22] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Column "DATETIME" cannot be found or is not specified for query. (13865)'
I’m not sure if it should work with convert and I’m doing something wrong, or there is another way to get this.
I’m trying to get automatically all table values with one operation to fill a DataTable object that I will throw to another table with SqlBulkCopy, that’s why I’m using this way to work. The source database is a Progress that I’m accessing with odbc connection and the ending database is SQL
Advertisement
Answer
I’ve finally found the solution. With progress database you have to pass the datatimes in different format. Passing datetimes without convert and in this format worked for me: ‘YYYY-mm-dd’, but if you have the year, month or day into a variable you have to pass like ‘@YEAR@’ + ‘-‘ + ‘@MONTH@’ + ‘-‘ + ’01’ Because there is a lot of information and it still crashes because timeout, I’ve done different ranges of datetimes to solve it.
SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" < '1900-01-01' SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" < '2000' + '-' + '01' + '-' + '01' AND "RHMC-fecmov" > '1900' + '-' + '01' + '-' + '01' SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" < '2010' + '-' + '01' + '-' + '01' AND "RHMC-fecmov" > '2000' + '-' + '01' + '-' + '01' SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" < '2015' + '-' + '01' + '-' + '01' AND "RHMC-fecmov" > '2010' + '-' + '01' + '-' + '01' SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" < '2020' + '-' + '01' + '-' + '01' AND "RHMC-fecmov" > '2015' + '-' + '01' + '-' + '01' SELECT * FROM AUTO05AS.PUB.rhiscab where "RHMC-fecmov" > '2020-01-01'