Link to home
Start Free TrialLog in
Avatar of Darius
DariusFlag for Lithuania

asked on

TSQL - JOIN tbl columns nvarchar with int

Hi Guys,

Working with JOIN

This query working
select
	  d.documentId
	, d.userSenderId
	, d.userRecipientId
    , s.name as SenderName
    , r.name as RecipientrName
from documents AS d
inner join users AS s on d.userSenderId = s.userId 
inner join users AS r on d.userRecipientId = r.userId 

Open in new window


Need to join one more column 'accountNumber' onUsers table
select
	  d.documentId
	, d.userSenderId
	, d.userRecipientId
    , s.name as SenderName
    , r.name as RecipientrName
   , ua.accountNumber AS AccountNumber
from documents AS d
inner join users AS s on d.userSenderId = s.userId 
inner join users AS r on d.userRecipientId = r.userId

inner join Users AS ua on d.recipientUserId = cast(cast(ua.accountNumber as float)as numeric(10,0)) 

Open in new window


When I tried to JOIN accountNumber column , -no errors but is no output results as well!!!
recipientUserId  (int)
accountNumber  (nvarchar)


Please assist!
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darius

ASKER

got this exception

The conversion of the nvarchar value '4986400000' overflowed an int column.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darius

ASKER

Thanks Pawan!
Welcome Darius. Glad to help. !!
There is no conversion in Scott's solution unless I am missing something. You may want to post the exact TSQL produced this error.