My resume is to implement an interface that has a method that looks something like this: GetValuesSqlStatement below:
public string SqlPattern { get { ... } } //this varies; eg. "SELECT name FROM someTable WHERE startDate < {0}" public string DatabaseType { get { ... } } //this varies; eg. "SqlServer" public string GetValuesSqlStatement(List<object> paramValues) { //...desired logic here, using DatabaseType, SqlPattern and paramValues }
Now, since this should lead to the execution of the executable SQL statement, I cannot use the parameters when executing the query. And the interface I have to implement is not negotiable. What is the best way to make sure the dates in the results are interpreted correctly by the database query engine? Assuming paramValues ββcontains .NET DateTime objects, how should they be formatted into a string before connecting to a SQL template string? What is the most common universal date format in required databases? (for example, something like "dd-mmm-yyyy").
NB: I really need to worry about Sql Server from 2005 and Oracle 10g onwards. Thus, SQL must be valid T SQL and PL SQL and means the same thing in both cases.
source share