SQL Server:从字符串转换为uniqueidentifier时,转换失败

SQL Server:从字符串转换为uniqueidentifier时,转换失败,sql,sql-server,stored-procedures,type-conversion,Sql,Sql Server,Stored Procedures,Type Conversion,在过去的一个小时里,我一直在努力解决这个问题,sql给了我以下错误 Msg 8169, Level 16, State 2, Procedure GetAppointmentsByProfessionalName, Line 6 Conversion failed when converting from a character string to uniqueidentifier. 当执行此存储过程时 -- ======================================

在过去的一个小时里,我一直在努力解决这个问题,sql给了我以下错误

Msg 8169, Level 16, State 2, Procedure GetAppointmentsByProfessionalName, Line 6
Conversion failed when converting from a character string to uniqueidentifier.
当执行此存储过程时

    -- =============================================
    -- Create date: <July 2010>
    -- Description: <Gets a list of appointments for a professionals username>
    -- =============================================
    Drop procedure GetAppointmentsByProfessionalName
    go
    Create procedure GetAppointmentsByProfessionalName(@ProfessionalName varchar(256))
    as
     declare @ProfessionalID uniqueidentifier
     set @ProfessionalID = (select UserId from aspnet_Users where UserName = @ProfessionalName)

     select a.AppointmentID as 'Appointment ID', 
       c.Name as 'Client Name', 
       p.Name as 'Professional Name', 
       a.ProposedDate as 'Date', 
       CONVERT(CHAR(8), a.ProposedTime, 114)as  'Time', 
       a.ClientDescription as 'Client Notes', 
       a.Confirmed as 'Confirmed Appointment'
     from Appointment a join Client c on a.ForClientID = c.ClientID
          join dbo.Professional p on a.ForProfessionalID = p.ProfessionalID
     where ForProfessionalID = @ProfessionalName
    go

这可能是一个语法问题,我对SQL还不是很在行。我希望这里的人能够发现我的问题。

您的存储过程接受
varchar(256)
,但是您的
语句连接到
forProfessional ID
,这是一个唯一标识符。

您的存储过程接受
varchar(256)
,但是您的
WHERE
语句连接到了
ForProfessional ID
,这是一个唯一的标识符。

问题是:

where ForProfessionalID = @ProfessionalName
我想你想要

where ForProfessionalID = @ProfessionalID
问题是:

where ForProfessionalID = @ProfessionalName
我想你想要

where ForProfessionalID = @ProfessionalID

哦!我完全是想把@ForProfessional ID放在那里的,谢谢。我希望我能不止一次地投这一票。没有什么比被小波比的桌子抓到了脑筋急转弯的时刻更让人兴奋的了!哦!我完全是想把@ForProfessional ID放在那里的,谢谢。我希望我能不止一次地投这一票。没有什么比被小波比的桌子抓到了脑筋急转弯的时刻更让人兴奋的了!