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 2008 Forums
 Transact-SQL (2008)
 Table with dynamic name caused loading slow

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-11-30 : 05:35:18
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.

Regards,
Micheale

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-11-30 : 05:43:28
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
   

- Advertisement -