What is the timeout of a query in SQL Server 2008
To answer the specific question: by default there is no timeout while running a query against the database engine. It will happily wait or days for an operation to complete whether the delay is due to the actual statement taking a long time to process or due it being sat waiting for other connections to release relevant locks.

Standard connection libraries like ADO implement timeouts, after which they will tell SQL Server to cancel the current operation and drop the connection.

There are timeout settings governing various processes (login processes, or situations where the database engine itself is asking a remote resource to perform some action, and such) but these do not affect queries given direct to the database engine.

For more specific help you'll need to add further details (the code of your query, the exact error message, perhaps some notes on your structure (is "#tablename# the name of an actual table in your DB?) so we can see if there is something there that would cause the error you have seen.