Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:17:22+00:00 2026-05-15T19:17:22+00:00

I have a (MS) SQL VIEW with no control over and it also queries

  • 0

I have a (MS) SQL VIEW with no control over and it also queries several other SQL VIEWs that I also have no control over but must use.

Get all rows based on “pilot” value except where it starts with 402 or 403, or A40. This is the current query that works fine as long as all “pilot” entries are possible to interpret as INT.

SELECT * from sqlsrvlink.DATABASE.dbo.V_PILOT_GENERAL WHERE NOT LEFT(pilot,3) IN ('402','403')

The pilot should always be an INT but the SQL design leaves much to desire and is implemented as a VARCHAR. Therefore it’s possible, for 3:rd party application with no input format checks, to ‘configure’ the “pilot” column to include none numerical values and in that case my SELECT statement fails with error message:

Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value ‘A406XX’ to a column of data type int.

How can I expand the SELECT to also exclude A40, but mainly workaround the ‘converting error of VARCHAR to INT’ by excluding or bluntly ignore them (none numerical values).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:17:23+00:00Added an answer on May 15, 2026 at 7:17 pm
    SELECT * from sqlsrvlink.DATABASE.dbo.V_PILOT_GENERAL
    WHERE pilot NOT LIKE '402%' AND pilot NOT LIKE '403%' AND pilot NOT LIKE 'A40%'
    

    Should make better use of any index on pilot as well

    Edit

    Following your comment I think I misunderstood the problem originally. The issue is not with the SELECT statement itself but more when invalid data is in the base table any attempt to access that column in the offending row causes an error as below.

    CREATE VIEW [dbo].[testing] 
    AS
    SELECT 1 AS [Number]
          ,'X' AS Letter
      union all
    SELECT 'bob' AS [Number]
          ,'Y' AS Letter
      union all
    SELECT 3 AS [Number]
          ,'Z' AS Letter
    GO
    
    SELECT * /*Works*/
    FROM  [dbo].[testing] 
    WHERE Letter IN ('X', 'Z')
    
    SELECT CAST([Number] AS varchar(10)) /*Error Occurs*/
    FROM  [dbo].[testing] 
    

    I’m not aware of any way of avoiding this without changing the View definition (which you say you can’t do) or changing the base data, or rewriting the query to not use the view. You won’t be able to filter on that column to remove dodgy records as the attempt to use it in a filter will just cause the error to occur.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SSIS package that queries data from a view using an SQL
I have a MS SQL view that I want to make available as a
I have an SQL Server Reporting Services (SSRS) report, that uses a view. That
I have a dataset that points to a View in my SQL database, and
I have RO access on a SQL View. This query below times out. How
I have created a simple view consisting of 3 tables in SQL. By right
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I have SQL data that looks like this: events id name capacity 1 Cooking
I have a list view with a HyperLink control within the ItemTemplate. I want
I am new to asp.net. I have a details view control on my page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.