本文介绍了动态查询中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
选择查询没有返回任何值
QUERY:
SELECT
纬度,
经度
FROM
table
WHERE
Device_DateTime BETWEEN ' 2014-03-26 14:18:00.000' AND ' 2014-03-26 14:19:00.000';
- 上面的查询返回值
但是如果是Dyanamic查询:
SELECT @ SQL = N ' 选择纬度,经度来自dbo。 + @ tablename +
' WHERE Device_DateTime BETWEEN''' + @ MinId + ' ''AND''' + @ toDateTime + ' ''
EXEC sp_executesql @SQL
- 以上查询返回错误,比如从字符串转换日期和/或时间时转换失败。
所以我将Query更改为CAST( Device_DateTime as NVARCHAR(50))
它没有给出任何错误但值为空..
任何帮助都可以被赞赏...
解决方案
Hi everybody,
Select Query is not returning any values
QUERY:
SELECT Latitude, Longitude FROM table WHERE Device_DateTime BETWEEN '2014-03-26 14:18:00.000' AND '2014-03-26 14:19:00.000';
-- The above Query is returning values
But in case of Dyanamic Query:
SELECT @SQL=N'SELECT Latitude,Longitude FROM dbo.' + @tablename + ' WHERE Device_DateTime BETWEEN ''' + @MinId + ''' AND ''' + @toDateTime + ''' EXEC sp_executesql @SQL
--The above Query is returning Error like Conversion failed when converting date and/or time from character string.
So i changed Query as CAST(Device_DateTime as NVARCHAR(50))
Its not giving any error but values are empty..
Any help can be appreciated...
解决方案
这篇关于动态查询中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!