Sql server 存储过程中的“select”语句不工作

Sql server 存储过程中的“select”语句不工作,sql-server,Sql Server,我曾尝试通过使用内部联接实现一个存储过程来显示来自不同表的结果,但我的问题是select语句没有返回任何结果,而是将一些值打印为消息 alter proc EmployeeReport(@empid int) as begin declare @inTime time(0) declare @outTime time(0) declare @fromDate date declare @toDate date set @inTime = (select CAST(InTime as time(

我曾尝试通过使用内部联接实现一个存储过程来显示来自不同表的结果,但我的问题是select语句没有返回任何结果,而是将一些值打印为消息

alter proc EmployeeReport(@empid int)
as
begin
declare @inTime time(0)
declare @outTime time(0)
declare @fromDate date
declare @toDate date

set @inTime = (select CAST(InTime as time(0)) from Timelog where EmployeeId=@empid)
set @outTime = (select CAST(OutTime as time(0)) from Timelog where EmployeeId = @empid)
set @fromDate = (select cast (InTime as date) from Timelog where EmployeeId= @empid)
set @toDate = (select cast (outTime as date) from Timelog where EmployeeId= @empid)

select @fromDate as FromDate
      ,@toDate as ToDate
      ,c.Name as Client
      ,p.Name as Project
      ,@inTime as InTime
      ,@outTime as OutTime
      ,t.TotalTime
from Timelog t
    inner join Employee e
        on e.id = t.EmployeeId
    inner join Project p
        on p.Id = t.EmployeeProjectId
    inner join Client c
        on c.Id = p.ClientId
where t.EmployeeId = @empid

 print @inTime
 print @outTime
 print @fromDate
 print @toDate
 end
我附加的输出文件,我得到什么,请帮助我这个

正在打印的Messeges:

未返回或选择任何值:


初始声明设置仅从TimeLog表中选择数据,该表显然包含数据。因为您将从这里内部连接到其他表,如果这些其他表没有数据,则不会返回任何内容

请确保Employee、Project和Client表中包含数据,或者将联接更改为左侧而不是内部:


请检查您的连接。另外,select语句中缺少where子句。我尝试使用where子句,但仍然不起作用。您不需要所有这些变量,只需在查询中选择这些变量即可。如果你想保留变量,你应该在一个select语句中而不是在4个语句中。
select @fromDate as FromDate
      ,@toDate as ToDate
      ,c.Name as Client
      ,p.Name as Project
      ,@inTime as InTime
      ,@outTime as OutTime
      ,t.TotalTime
from Timelog t
    left join Employee e
        on e.id = t.EmployeeId
    left join Project p
        on p.Id = t.EmployeeProjectId
    left join Client c
        on c.Id = p.ClientId