当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Conversion failed when converting from a character string to uniqueidentifier - why?

问题描述:

I am getting this error when running:

SELECT *

FROM repsresidents rr

LEFT JOIN

(SELECT *

FROM residents r1

INNER JOIN

(SELECT res_peopleidy AS peopleidy,

min(res_id) AS RES_ID2

FROM residents

WHERE res_active = '1'

GROUP BY res_peopleidy) r2 ON r1.res_id = r2.res_id2) r ON rr.mainpeopleidy = r.res_peopleidy

WHERE rr.communityidy = 1

I believe the problem is on min(res_id) AS RES_ID2 because res_id is a PK.

Here's the schema of residents table

CREATE TABLE [dbo].[Residents](

[RES_ID] [int] IDENTITY(1,1) NOT NULL,

[RES_PeopleIDY] [varchar](50) NOT NULL,

[RES_PhyMoveInDate] [datetime] NULL,

[RES_CurrentUnitNumber] [varchar](50) NULL,

[RES_CommunityIDY] [int] NULL,

[RES_DateStarted] [datetime] NULL,

[RES_NoPart] [int] NULL,

[RES_LastUserUpdated] [int] NULL,

[PER_ID] [int] NULL,

[HEA_ID] [int] NULL,

[LIF_ID] [int] NULL,

[INT_ID] [int] NULL,

[TES_ID] [int] NULL,

[STA_ID] [int] NULL,

[STA_Type] [int] NULL,

[NetworkSet] [int] NULL,

[RES_Active] [int] NULL,

[RES_HasImage] [int] NULL,

[RES_UpdatedImage] [int] NULL,

[RES_Bio] [text] NULL,

[RES_BioUpdate] [datetime] NULL,

[RES_BioUpdateBy] [int] NULL,

[ACT_ID] [int] NULL,

[RES_LobbyBio] [varchar](max) NULL,

[RES_LobbyBioUpdate] [datetime] NULL,

[RES_LobbyBioUpdateBy] [int] NULL,

[RES_DiscNotes1] [varchar](max) NULL,

[RES_DiscNotes2] [varchar](max) NULL,

[RES_DiscNotes3] [varchar](max) NULL,

[RES_DiscNotes4] [varchar](max) NULL,

[RES_DiscNotes5] [varchar](max) NULL,

[RES_ExpiredDate] [datetime] NULL,

[RES_ExpiredUser] [int] NULL,

[RES_FinishedDate] [datetime] NULL,

[RES_TasksSet] [int] NULL,

CONSTRAINT [PK_Residents] PRIMARY KEY CLUSTERED

(

[RES_ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

What am I doing wrong?

网友答案:

Since there are no UNIQUEIDENTIFIERS on Residents, I would have to believe that your issue is with RepsResidents. Any chance that mainpeopleidy is a uniqueidentifier?

分享给朋友:
您可能感兴趣的文章:
随机阅读: