Help needed for Data Type Conversion

  • 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

  • The error is happening here:- on t2.vp_name=bp.id

    vp_name is a VARCHAR and ID is a UNIQUEIDENTIFIER

  • 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

  • Yes, the conversion needs to be in the join

  • 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))

  • Thank you.

    It is working fine now.

  • No worries!

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply