How to fix Msg 245, Level 16, State 1, Line 3 Conversion failed when converting the nvarchar value 'N/A' to data type int. on SQL

Arthur Felipe do Lago Montenegro 20 Reputation points
2024-04-10T19:54:59.86+00:00

Hey guys

I am using this code
SELECT*

FROM [dim].[ServiceOrder] AS SO

INNER JOIN [dim].[Turbine] AS TB ON SO.[Room] = TB.[Unitid]

WHERE

[ServiceOrderStatusOrderNumberText] = 'Planned'

AND [TB].[SBU] = 'LAT'

and [ScheduledStart] > GETDATE()

I shows this error: Msg 245, Level 16, State 1, Line 3

Conversion failed when converting the nvarchar value 'N/A' to data type int.

can you guys help with that?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,785 questions
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 27,016 Reputation points
    2024-04-11T01:34:09.75+00:00

    Hi @Arthur Felipe do Lago Montenegro

    Try using TRY_CAST() or TRY_CONVERT() to convert the nvarchar value to data type int. If the conversion fails, it returns NULL.

    FROM [dim].[ServiceOrder] AS SO
    INNER JOIN [dim].[Turbine] AS TB ON Try_Cast(SO.[Room] As int) = TB.[Unitid]
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.