Msg 8169, Level 16, State 2, Line 1 Conversion failed when converting from a character string to uniqueidentifier.


hello,

i have admit bad sql. have scenario 1 of tfs 2015 view stores team project name guid which is of type nvarchar. need provide users name of projects rather id in report. have view in tfs 2015 gives me name of projects. thought of writing join statement 2 views , project names. went below query , keep on same page, team project name in first view has guid , name well. older projects migrated tfs 2012.

system.teamproject has team project name (older project name tfs 2012) , id new projects (tfs 2015). in short has names , id's stored in it. want names output in report to further report set up.

select * [dbo].[vw_denorm_workitemcorelatest] wi
inner join [dbo].vw_projects p on wi.[system.teamproject] = p.project_id
union all
select * [dbo].[vw_denorm_workitemcorelatest] wi
inner join [dbo].vw_projects p on wi.[system.teamproject] = p.project_name

for have * in query. know second part of query works fine , return data projects has name stored. however guid id return error.

msg 8169, level 16, state 2, line 1 conversion failed when converting character string uniqueidentifier.

i have checked issue online , saw many suggestions. still not able solve it. understood 1 nvarchar , project_id uniqueidentifier. however modification should make in sql query ? 

first view:

second view: 

thanks & regards,

ahetejazahmad khan.


ahetejazahmad khan.

ok, have resolved issue based on vishe and  hilary inputs. below correct query , correct type casting.

select distinct p.project_name, p.project_id [dbo].[vw_projects] p
inner join [dbo].[vw_denorm_workitemcorelatest] wi
on wi.[system.teamproject] = convert(nvarchar(36), p.project_id)
or  wi.[system.teamproject] = p.project_name

hopefully useful others.

thanks & regards,

ahetejazahmad khan.


ahetejazahmad khan.



SQL Server  >  Getting started with SQL Server



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........