我尝试使用内连接实现一个存储过程来显示来自不同表的结果,但我的问题是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打印出来:
没有返回值或已选择:
答案 0 :(得分:4)
您的初始声明仅设置select
表中的TimeLog
数据,其中明确包含数据。因为那时inner join
从这里到其他表,如果那些其他表没有数据,则不会返回任何内容。
要么确保您的Employee
,Project
和Client
表格中包含数据,要么将join
更改为left
而不是{{1} }}:
inner