Merge two DataColumns of type DateTime
i have a datatable which contains two Datacolumns (date_start,date_sent) and i wanted to merge them into one single column (date_order) to then apply a sort like this:
DataRow[] dtSorted = dt.Select(null, "date_order DESC",DataViewRowState.CurrentRows);
Since whenever date_start is null开发者_C百科, date_sent is not and vice versa, i tried the following expression to the datacolumn:
dt.Columns.Add("date_order", typeof(String), "IIF(date_start=NULL,date_sent,date_start)");
but its not working.Tried something like "ISNULL(date_start,date_sent),date_start" and "date_start + date_sent" but they didn't work either.
Can someone please tell me what expression i should use? Thank you.
You should use the SQL COALESCE keyword, which returns the first non-null argument, e.g.:
SELECT COALESCE(date_order, date_sent) ...
That will return the first non-null out of date_order and date_sent
If you are doing it in C#...?? is the Null Coalescing operator you should be looking for I think...basically equivalent to isnull in tsql.
精彩评论