提问人:Fausto Galati 提问时间:10/3/2023 最后编辑:Dale KFausto Galati 更新时间:10/4/2023 访问量:47
sp_get_query_template不适用于 ODBC 时间戳
sp_get_query_template doesn't work with ODBC timestamp
问:
我有以下疑问:
SELECT COUNT(*)
FROM (
SELECT DISTINCT USER_NAME
FROM LICENSE
WHERE RESTRICTED_USE = 'T'
AND ALLOCATED = 'T'
UNION ALL
SELECT USER_NAME
FROM LICENSE
WHERE RESTRICTED_USE = 'T'
AND ALLOCATED = 'F'
AND "TIME" >= {ts '2023-10-02 08:09:12'}
) AS TEMP_ALIAS
当我尝试使用sp_get_query_template创建计划指南时,计划指南不起作用,我认为原因是ODBC时间戳值。
DECLARE @stmt nvarchar(max);
DECLARE @params nvarchar(max);
EXEC sp_get_query_template
N'SELECT COUNT(*) FROM (SELECT DISTINCT USER_NAME FROM LICENSE WHERE RESTRICTED_USE = ''T'' AND ALLOCATED = ''T'' UNION ALL SELECT USER_NAME FROM LICENSE WHERE RESTRICTED_USE = ''T'' AND ALLOCATED = ''F'' AND "TIME" >= {ts ''2023-10-02 08:09:12''})AS TEMP_ALIAS',
@stmt OUTPUT,
@params OUTPUT;
select @stmt
select @params
EXEC sp_create_plan_guide
N'UsersCountTable',
@stmt,
N'TEMPLATE',
NULL,
@params,
N'OPTION(PARAMETERIZATION FORCED)';
我也尝试将时间戳参数指定为: VARCHAR()、DATEATIME、SMALLDATETIME DATETIME2 没有成功。
答:
评论
AND "TIME" >= {ts '2023-10-02 08:09:12'}
T-SQL 无效吗?SELECT COUNT(DISTINCT USER_NAME)