Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] join on character and integer

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-04-15 : 11:51:10
Have following and not sure if possible to get around this:

Variable carrier is an integer and vessel is a char(20), is there a way to do the join (getting error: Conversion failed when converting the varchar value 'Colonial Pipeline' to data type int)

I only need to do the join in variable vessel has a numreic value (otherwise not).

Thank you.

LEFT JOIN [VEMA-FACS1].FUELFACS.dbo.carrier as ca ON ca.carrier_number = bm.vessel

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-15 : 12:09:15
LEFT JOIN [VEMA-FACS1].FUELFACS.dbo.carrier as ca
ON ca.carrier_number = case when isnumeric(bm.vessel)=1 then convert(int,bm.vessel) end


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-04-15 : 12:38:19
Great. Thank you. Worked purrrfectly.
Go to Top of Page
   

- Advertisement -