Convert nvarchar to int in order to join SQL tables in a view Convert nvarchar to int in order to join SQL tables in a view sql sql

Convert nvarchar to int in order to join SQL tables in a view


Looking at your code, I can't tell either what you should do.

The SQL engine will do automatic conversions for the comparison. However, if might decide to convert the character field to an integer -- and then get an error.

So, just cast your int field to nvarchar:

cast(IntField as nvarchar(255))

The length doesn't matter for an nvarchar() comparison.

In your query, you would replace:

ON dbo.pck_hdr.pack_num = dbo.STR_ShipTrack.Reference1

with:

ON cast(dbo.pck_hdr.pack_num as nvarchar(255)) = dbo.STR_ShipTrack.Reference1