View Full Version : T-sql


accessman2
11-14-2006, 12:19 PM
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
11-14-2006, 01:17 PM
This can be done a couple ways and should also answer your other post.

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

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] = ...