如何编写涉及时间戳的SQL查询?
QUOTE_ID is a character string
CREATE_DTG is a date time type
RETENTION_LEAD_TRACK is a table
这个sql语句
cmf.CommandText = "SELECT QUOTE_ID FROM RETENTION_LEAD_TRACK where CREATE_DTG > '2016 - 04 - 25 18:18:15.2891'"
抛出此错误 {"从字符串转换日期和/或时间时转换失败。"}
答案 0 :(得分:2)
2016 - 04 - 25
有空格。把那些拿出来
SELECT QUOTE_ID
FROM RETENTION_LEAD_TRACK
where CREATE_DTG > '2016-04-25 18:18:15.2891'
答案 1 :(得分:1)
试试这个cmf.CommandText = "SELECT QUOTE_ID FROM RETENTION_LEAD_TRACK where CREATE_DTG > convert(datetime2,'2016 - 04 - 25 18:18:15.2891')"
谢谢