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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Table with dynamic name caused loading slow
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

232 Posts

Posted - 11/30/2012 :  05:35:18  Show Profile  Reply with Quote
Hi All,

I have 2 SP:-

1. Use a lot of

set @sSQL=@sSQL+' from tbl'+@username+' '
OPEN contact_cursor;
FETCH NEXT FROM contact_cursor

Time Taking for same sql statement when print @sSQL: 2:50:45

2. ... from tbl
OPEN contact_cursor;
FETCH NEXT FROM contact_cursor

Time Taking for same sql statement when print @sSQL: 00:50:45

May i know how can i perform all the table with dynamic name with faster speed? Coz all the table involved calculation & insert into the table created based on username.

Thank you.


Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 11/30/2012 :  05:43:28  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
What is the time for - the duration of the processing? i.e. from cursor open to close?

Try inserting into a temp table.
Then you can loop through the temp table (could use a cursor but no need).

I'm guessing the dynamic sql has an effect on the cursor processing - doing this will make the processing local to the statement and also make it easy to see whether it is the extract of the data that is the issue or the processing.

Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000