I have the following query:
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
When I try to create a plan guide with sp_get_query_template the plan guide doesn't work and I think that the cause is the ODBC timestamp value.
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)';
I've tried also specifying timestamp parameter as: VARCHAR(), DATEATIME, SMALLDATETIME, DATETIME2 with no success.
1条答案
按热度按时间wbrvyc0a1#
I thought that i've found the solution (thanks to Dale K comment)
I changed the query by removing the double quotes thinking that this would work but after a while those execution plans reappeared.