September 23, 2014 at 6:16 am
Hi,
I created temptables
create table #tempt1 (accountname nvarchar(50))
Create table #tempt2(vp_name nvarchar(50))
create table #temp3 (VP_Id varchar(50) null, Organisation_id bigint null)
Insert into #temp3 (vp_Id)
select bp.id from #temp2 as t2
join plan bp
on t2.vp_name=bp.id
Note: Here Plan is the physical table and the id column is Pk, UniqueIdentifier
when I execute the query, I am getting conversion failed from character string to uniqueidentifier.
so I use the following
Insert into #temp3 (vp_Id)
select cast((bp.id) as varchar(50))
from #temp2 as t2
join plan bp
on t2.vp_name=bp.id
But still I am getting the same error message conversin failed from character string to unique identifier.
Any help would appreciate
Thanks
September 23, 2014 at 6:20 am
The error is happening here:- on t2.vp_name=bp.id
vp_name is a VARCHAR and ID is a UNIQUEIDENTIFIER
September 23, 2014 at 6:48 am
Yes. I understand the error but when I use the cast function, it has to change the datatype but still I am getting issue
select cast((bp.id) as varchar(50))
bp is the table alias
Id is uniqueidentifier, I need to change into varchar.
Is anything wrong with this above conversion
September 23, 2014 at 7:00 am
Yes, the conversion needs to be in the join
September 23, 2014 at 7:03 am
Try:-
select cast((bp.id) as varchar(50))
from #temp2 as t2
join plan bp
on t2.vp_name=cast((bp.id) as varchar(50))
September 23, 2014 at 7:34 am
Thank you.
It is working fine now.
September 23, 2014 at 7:38 am
No worries!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply