To reduce the execution Time

Yes and no.

If the entire column contains ONLY data that can be converted to an INT, then yes, it will work. If you have even just one "non-int-convertible" value in the column, it will fail.

Now, even if it does work, the title of this thread is "To Reduce the Execution Time". Having that column as a VARCHAR and then comparing it to integers will cause an explicit conversion on every row in the entire table. In other words, it's non-SARGable and it will never do a high performance index seek (followed by a range scan) to locate the first row meeting the criteria. And, if you change it to look for the value of '110' instead of just 110, then you can and will come up with the wrong answers because the character based value of '2' is greater than the character based value of '110' because of the left to right evaluation of characters.

The bottom line here is that you have a temp table. You NEED to make the column the correct datatype to correctly and quickly do lookups on it. You should probably consider changing the datatype in the real table, as well.

Here's some code that demonstrates some of what I say...

--===== Create the test table and related index.
 SELECT TOP 200
        VarCharNumber = CAST(ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS VARCHAR(10))
   INTO #MyHead
   FROM sys.all_columns
;
CREATE UNIQUE CLUSTERED INDEX IXC_#MyHead ON #MyHead (VarCharNumber)
;
GO
--===== Do the original search with the execution plan on
     -- to see that a seek did not occur.
 SELECT *
   FROM #MyHead
  WHERE VarCharNumber >= 110
;
GO
--===== Do a search to see that the wrong values are returned
     -- if we do a character based search.
 SELECT *
   FROM #MyHead
  WHERE VarCharNumber >= '110'
;
GO
--===== Change one value in the column to a word
     -- instead of a number.
UPDATE #MyHead
SET VarCharNumber = 'Test'
WHERE VarCharNumber = 50
;
GO
--===== Show that the previous numeric searcch code now fails.
 SELECT *
   FROM #MyHead
  WHERE VarCharNumber >= 110
;
GO
1 Like

Totally understood, Thank you so much