(morleyc@gmail.com) writes:
[quoted text, click to view] > Thanks for the reply, so for my scenario of generating a load of new
> records would be ideal and is standard practice to use a stored
> procedure on the server? How would i go about stopping the procedure
> being called many times, and would it be possible to have a progress
> report (as it will be generating a lot of records) - in other words
> are there any callbacks on progress the front end could hook into on
> the server?
Toto, you are not in Kansas anymore.
No, there are no callbacks, and progress report is not really the same
thing anyway.
If you program in C# it may be easy, you set up a loop from 1 to whatever
and of you go.
In SQL you should, preferrably, work with a sets of data at a time. As
very simple case, say that you need update the salaries for all employees.
All get a 3% raise, but those who earn less than 20000 SEK/month get
a raise of 600. Since this raise is from 2007-03-31, employees who
left the company before this date should not be updated. This is how you
write this in SQL:
UPDATE employees
SET salary = CASE WHEN salary <= 20000
THEN salary + 600
ELSE salary * 1.03
END
WHERE enddate < '20070331'
Progress for this type of query is necessarily not meaningful, least
of all the query becomes more complex.
And why would you not write the above as a loop? The answer is performance.
If you would write the above as a loop and there are 10000 employees, it
could take several minutes for it to complete. The UPDATE statement will
complete in less than five seconds. (Probably subsecond).
Programming in SQL is a different mindset, and there is all reason
to learn the basics. Not only how, but also why.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at