What Is {Ts '2013-04-02 00:00:00'}

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



Leave a reply



Submit