T-sql (1 Viewer)

accessman2

Registered User.
Local time
Yesterday, 22:26
Joined
Sep 15, 2005
Messages
335
Hi,

I have a question.

In Query statement, I create a new blank script,
and then I want to write like this

(select [employee] from [table1] where [Num]= 1) As [emp]


select [Meeting Time] from [Time] where [emp].[employee]

In the script, can I use this way?
I know that when we run the script, it will run every line code in order. But, I am not sure whether or not I can name the first statement result as [emp], and then refer it to the second statement.

Please let me know about this. Thanks.
 

pdx_man

Just trying to help
Local time
Yesterday, 22:26
Joined
Jan 23, 2001
Messages
1,347
This can be done a couple ways and should also answer your other post.
Code:
select [employee] , EmpID
INTO #MYEmp
from [table1] 
where [Num]= 1

select t.[Meeting Time] 
from [Time] t
(INNER | LEFT | RIGHT) JOIN #MyEmp m
  ON t.EmpID = m.EmpID      -- You must have something in common between [Time] and your employee table
where [emp].[employee] = ...

DROP TABLE #MyEmp
OR
Code:
select t.[Meeting Time] 
from [Time] t
(INNER | LEFT | RIGHT) JOIN (select [employee] , EmpID
       from [table1] 
       where [Num]= 1) m
  ON t.EmpID = m.EmpID      -- You must have something in common between [Time] and your employee table
where [emp].[employee] = ...
 

Users who are viewing this thread

Top Bottom