Showing posts with label fetch. Show all posts
Showing posts with label fetch. Show all posts

Monday, March 19, 2012

Explicit Transactions

I have an cursor that loops 720 times.
Each FETCH does 6 INSERTS.
Each FETCH the 6 INSERTs a total of 200-300 records appended.

Would explicit transactions speed up the cursor?

In Oracle, I would keep track of how many times I've looped, and commit every nth time. I would put a catch remainder COMMIT at the end of the procedure.

I've got the IF @.@.TRANCOUNT > 19 COMMIT TRAN (about 6k records), but say I had <= 19 remaining at the end of the cursor, how do you get those to commit? I tried to put an IF @.@.TRANCOUNT > 1 COMMIT TRAN, but that didn't work.

What's a good @.@.TRANCOUNT to commit at in this case?

Thanks crew,
CarlIs it possible to transform the cursor to a set based operation which may optimize the operation. can you post your code?|||Carl, Oracle is cursor heavy, and often requires their use. SQL Server is optimized for set-based operations, and cursors are usually the worst method of managing data.|||I was able to go set based with the sub procedure at the prompting of you folks. Perhaps I can get rid of this cursor as well. If I can

SELECT CASE x=y THEN INSERT INTO xyz (SELECT * from abc) END

Can you do stuff like this?|||INSERT INTO xyz
SELECT *
from abc
where x=y

...but you should enumerate your columns and avoid the use of "select *..."

explicit row access

I have a dataset with multiple tables. The datatable I need is called
InvoiceTemplate and has its tableadapter implemented to fetch data from the
sql server backend with a stored proc, which accepts a single parameter: an
integer determining the country.
When the dataset is filled I get the following data in my InvoiceTemplate
table:
Columns: name, value
Sample data (ntext, ntext):
'iName', 'Lene Espersen'
'iNumber', 'Faktura nr.'
'iUnits', 'Antal'
'iPrice', 'Pris'
Etc.
So I've got a textbox in the report designer which I need to fill with the
value from the row containing 'iUnits' (get the data 'Antal')?
How to make an elegant expression solution to this? Essentially I'm trying
to escape from table pivoting, as sql server 2000 has poor support for that.
That is can I do an vbscript filter expression against the dataset so I only
get the desired row value?
Best regards
Alekif you realy want to put it in a textbox you should solve this in the query.
If you use a list, table or matrix you can add a filter: Fields!NAME.Value ="iUnits"
"Alek Lynge" wrote:
> I have a dataset with multiple tables. The datatable I need is called
> InvoiceTemplate and has its tableadapter implemented to fetch data from the
> sql server backend with a stored proc, which accepts a single parameter: an
> integer determining the country.
> When the dataset is filled I get the following data in my InvoiceTemplate
> table:
> Columns: name, value
> Sample data (ntext, ntext):
> 'iName', 'Lene Espersen'
> 'iNumber', 'Faktura nr.'
> 'iUnits', 'Antal'
> 'iPrice', 'Pris'
> Etc.
> So I've got a textbox in the report designer which I need to fill with the
> value from the row containing 'iUnits' (get the data 'Antal')?
> How to make an elegant expression solution to this? Essentially I'm trying
> to escape from table pivoting, as sql server 2000 has poor support for that.
> That is can I do an vbscript filter expression against the dataset so I only
> get the desired row value?
> Best regards
> Alek
>
>