What is {ts '2013-04-02 00:00:00'}?
It's an ODBC literal escape sequence
ODBC defines escape sequences for date, time, and timestamp literals. The syntax of these escape sequences is as follows:
{ts 'value'}
where we can use it?
Anywhere where a datetime
value is expected. ("timestamp" is SQL Standard vernacular for what SQL Server calls datetime
).
Message 102 Level 15 error SQL Server: Incorrect syntax
This is not the correct format for ODBC escape sequences. It should be wrapped in {}
where T1.submit_date < {ts '2020-01-31 00:00:00'}
Conversion of C# datetime to sql server datetime is throwing an error
Your code - as it is now - will transfer any value on string level. This is a really bad approach. The implicit conversions taking place are highly depending on your system's settings (language and culture). The worst part is: This might work all great on your machine while you are testing it, but on a customer's system it breaks with strange messages. Happy Debugging :-(
Change your code like this
foreach (PropertyInfo prop in props) {
// Setting column names as Property names.
if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
dataTable.Columns.Add(prop.Name, prop.PropertyType.GetGenericArguments()[0]);
else
dataTable.Columns.Add(prop.Name, prop.PropertyType);
}
This will add the column - even if this is a nullable type - with the correct data type.
credits: This answer helped me
UPDATE Even simpler
(thx to Yves M. in a comment below the linked answer)
foreach (PropertyInfo prop in props) {
// Setting column names as Property names.
dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
}
SQL: How to select one record per day, assuming that each day contain more than 1 value MySQL
To get the first entry for every date you can do
select * from value_magnitudes
where id in
(
SELECT min(id)
FROM value_magnitudes
WHERE magnitude_id = 234
and date(reading_date) >= '2013-04-01'
group by date(reading_date)
)
Crystal Report Function for converting Seconds to Timespan format
You could easily alter my ElapsedTime() function to meet your needs.
Related Topics
Remove Only Leading or Trailing Carriage Returns
Pl/Sql- Get Column Names from a Query
Getting Maximum Value of Float in SQL Programmatically
How to Return Rows from a Declare/Begin/End Block in Oracle
How to Troubleshoot Ora-02049 and Lock Problems in General with Oracle
How to Substitute a Left Join in Sql
Oracle Pls-00363: Expression '' Cannot Be Used as an Assignment Target
How to Do a SQL Update in Batches, Like an Update Top
How to Update All Columns of a Record Without Having to List Every Column
Blank Out Duplicate Column Values in SQL Reporting Services
Updating One Column Based on The Value of Another Column
Preventing Deadlocks in SQL Server
What Does It Mean When The Size of a Varchar2 in Oracle Is Declared as 1 Byte
How Can My Application Benefit from Temporary Tables