Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Internal Working Mechanism in SQL Server

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-03-02 : 16:24:17
Iam using a stored procedure where the @emp_number is the input parameter and I want to know how internally this both queries work and which gives more performance....

SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM
tbl_emp_info
WHERE
emp_id = (
select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')
)

Here I declare a variable and get the max emp_id first and then pass it to the main query..Which one gives better performance and how does that internally fire in SQL server

Delcare @max_emp_id INT
SET @max_emp_id = select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')

SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM tbl_emp_info
WHERE emp_id=@max_emp_id

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-03-02 : 16:54:07
Please let me know if somebody knows how internally this query gets executed
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-03-02 : 16:57:57
You may be able to see for yourself. Have you compared the execution plans?
(tools | options | connection properties tab | set showplan_text)

run both queries. Sql server will output the execution plans for both.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -