2017-03-09 11 views
1

内部結合を使用して別のテーブルの結果を表示するためのストアドプロシージャを実装しようとしましたが、selectステートメントは結果を返しません。メッセージ。ストアドプロシージャの "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 [email protected]) 
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で私を助けてください取得していますどのような出力ファイルを添付しています:

値が返されないか、選択した:

+1

は、あなたの加入をしてください確認してください。また、あなたのselectステートメントにwhere句がありません –

+0

where句を使用してみましたが、まだ動作していません –

+1

これらの変数はすべてクエリで選択するだけでかまいません。変数を保持したい場合は、4ではなく1つのSELECTステートメントで行う必要があります。 –

答えて

4

最初の宣言の設定は、TimeLogテーブルのselectデータのみです。データには明らかにデータが含まれています。ここからinner joinを他のテーブルに転送するので、他のテーブルにデータがない場合は何も返されません。

どちらかあなたのEmployeeProjectClientテーブルはそれらのデータを持っているか、leftの代わりinnerにごjoin秒を変更することを確認してください:

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 
+0

ありがとうございました。 –

関連する問題