Here's an example of the scenario:
CREATE TABLE dbo.TestConversionTable
(
Value VARCHAR(MAX)
)
INSERT INTO dbo.TestConversionTable VALUES ('1')
INSERT INTO dbo.TestConversionTable VALUES ('foo')
CREATE VIEW dbo.TestConversion
AS
SELECT CONVERT(BIGINT,Value) Value
FROM dbo.TestConversionTable
WHERE Value <> 'foo'
GO
SELECT * FROM dbo.TestConversion --this works
SELECT * FROM dbo.TestConversion WHERE Value = 1 --Error converting data type varchar to bigint.
SELECT * FROM dbo.TestConversion WHERE Value = '1' --Same thing, this doesn't work either.
I would expect both the scenarios to work since the view already filters out the bad data. What's even stranger is that the second query does not work either. I can only grab an estimated execution plan on both of them (since I can't actually run the query without error), and they are identical. Based on the estimated plan, the bad data would be filtered first before the WHERE Value = 1
is applied.
Edit: To test the query plans, I changed the CONVERT to TRY_CONVERT instead. The result of the plans are still identical, and it looks like the filter occurs before the conversion: