我正在检查12/09/2016
到13/09/2016
的条件,但它没有显示13/09/2016
的数据并给出错误
将char数据类型转换为datetime数据类型会导致日期时间值超出范围。
这是我的查询
SELECT DISTINCT
b.mkey , a.N_UserMkey, cuser_id,isnull(a.N_UserMkey,cuser_id) aa,
ISNULL(b.first_name + ' ', '')
+ ISNULL(b.last_name, '') NAME, convert(varchar,a.U_datetime,103) Action_Date
FROM inward_doc_tracking_trl a
INNER JOIN user_mst b ON isnull(a.N_UserMkey,cuser_id) = b.mkey
WHERE
convert(datetime,a.U_datetime,103)
BETWEEN convert(varchar,'12/09/2016',103)
AND convert(varchar,'13/09/2016',103)
and b.mkey=2357
答案 0 :(得分:2)
我不确定,但似乎你在这里累积了几个错误:
- (IBAction)capture:(UIButton *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Code for Cam
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Gallery" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for Gallery
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Remove Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for removing photo
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = sender.bounds; // You can set position of popover
[self presentViewController:alert animated:TRUE completion:nil];
}
检查日期范围。由于日期时间的时间部分,这是非常错误的。经常被遗忘......你可以read this great blog by Aaron Betrand BETWEEN
convert(varchar,'12/09/2016',103)
中使用尝试将varchar
条款更改为此(9月12日的所有日期时间,但不是13日)
WHERE
或此(9月12日和9月13日的所有日期时间)
WHERE a.U_datetime >= {d'2016-09-12'} AND a.U_datetime<{d'2016-09-13'}
答案 1 :(得分:1)
您需要转换为DATETIME
...
BETWEEN convert(datetime,'12/09/2016',103)
AND convert(datetime,'13/09/2016',103)
目前查询只将BETWEEN参数保留为VARCHAR,然后服务器需要将它们与convert(datetime,a.U_datetime,103)
进行比较。在那一刻,它们被转换为DATETIME,没有指定格式。