SQl Server still getting the error of "Timeout expired. The timeout period elapsed"
Without regards to your timeout;
Are you using the sql management console to run your query? If so, when connecting to the database there is an options button that allows one to set the timeouts.
Also, if in the query window, right click and choose Query Options....
0, means unlimited, I would check these. 4 minutes is a long time, maybe the query can be refactored to run faster?
If you are running this inside of Visual Studio via C# the default command timeout is 30 seconds. Alter it by setting the command time out:
SqlCommand comm= new SqlCommand();
comm.CommandTimeout = 300;
If a query takes that long of time then it is probably something wrong. I would declare a variable to store the RecentTradingDateByNumber. So it looks like this:
DECLARE @RecentTrandingDateByNumber DATETIME
SET @RecentTrandingDateByNumber=dbo.RecentTradingDateByNumber(3)
SELECT
tblSymbolsMain.Symbol,
MAX(tblSymbolsMain.TradeDate)
FROM
tblSymbolsMain
GROUP BY
Symbol
HAVING
MAX(TradeDate) < @RecentTrandingDateByNumber
To see the execution in management studio go to "Query/Include Actual Execution Plan". If you also want to see the traffic of the query the numbers of select etc. You can also include the client statistics. "Query/Include client statistics"
If you want to know more information about examining the queries execution see here