question

sureshg avatar image
sureshg asked

Read records from table without using Cursor

I have 2 tables(Table A & Table B).I wish to read one by one records from Table A and compare with Table B.Currently we have use cursor for this purpose.But the SQL Server is waiting on the I/O to complete after a Log block in cache is flushed from Memory to Disk. Any body know about alternative solution to avoid cursor.It will very helpful to me.
sql-server-2008ms sql
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

srutzky avatar image srutzky commented ·
You might need to post your code in order for anyone to understand what is going on. Why aren't you simply JOINing the tables in a query? Or if a cursor approach is necessary, how do you have the cursor declared? Are you using the `STATIC LOCAL READ_ONLY FORWARD_ONLY` keywords that typically make cursors much more efficient? If not, why not? There is too little info here to go on.
2 Likes 2 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
It rather depends on what you're trying to identify / do with the tables. If you just want to identify records in table A that don't have corresponding items in Table B, it's relatively straightforward. If, on the other hand, you want to then *create* those records, or do something else, it might be a bit trickier. ...and what does the I/O logblock have to do with it? How do you know it's as a result of what you're doing?
1 Like 1 ·

1 Answer

·
sureshg avatar image
sureshg answered
Table A values CustID transID Group Count 1 5 T1 20 1 6 T1 10 1 7 T1 30 Table B values CustID transID Group Count 1 8 T2 5 1 9 T2 20 1 10 T2 10 Currently I have introduce 2 cursors,1 for table A and another for Table B read the records from both tables and compare the count and balance should be retain to next level. EG :read transID 5 & 8,and compare the count (20,5) get the min count(5). The rest of the count 15 compare with transID 5 & 9 and compare the count (15,20) for this line balance count is available in transID 9(balance count is 5) Then compare with transID 6 & 9 this process is continues this way. cursors details. declare group1_cursor cursor local read_only type_warning for select * from Table A declare group2_cursor cursor local read_only type_warning for select * from Table B
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.