I\'m trying to determine the relative performance of two different queries and have two ways of measuring this available to me:
1. Run both and time each query
2. Ru
Query Execution Time:
DECLARE @EndTime datetime
DECLARE @StartTime datetime
SELECT @StartTime=GETDATE()
` -- Write Your Query`
SELECT @EndTime=GETDATE()
--This will return execution time of your query
SELECT DATEDIFF(MILLISECOND,@StartTime,@EndTime) AS [Duration in millisecs]
Query Out Put Will be Like:

To Optimize Query Cost :
Click on your SQL Management Studio

Run your query and click on Execution plan beside the Messages tab of your query result. you will see like
