| Author |
Topic |
|
bubix
Starting Member
24 Posts |
Posted - 2005-11-18 : 02:26:28
|
| Hello,I would like to fetch rows from a table.I want first to fetch the first ligne then the next up to the last row of a table.I know we can do that with a cursor and Fetch next statement but how can we do that(extract rows) in a another way??? |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-11-18 : 02:50:12
|
| http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxNathan Skerl |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-18 : 03:01:20
|
| >>how can we do that(extract rows) in a another way???Select columns from yourTableMadhivananFailing to plan is Planning to fail |
 |
|
|
bubix
Starting Member
24 Posts |
Posted - 2005-11-18 : 03:13:21
|
| Hello nathans,Sorry for my explications, but I must extract the first row from a table then work with this row.Then I must extract the second row and work with too. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-18 : 03:15:13
|
quote: Originally posted by bubix Hello nathans,Sorry for my explications, but I must extract the first row from a table then work with this row.Then I must extract the second row and work with too.
What are you actually trying to do?Post table structure, sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
bubix
Starting Member
24 Posts |
Posted - 2005-11-18 : 03:28:04
|
| Sample:I have a trigger after update on table_B1. I update a field of set of rows from table_B IN THE SAME TIME2. In my trigger, the deleted table contains old values of the field which is updated.2. I use deleted Table to extract old value of field of each row. This value is used to do a comparison.3. I must extract the second row from deleted table to use old value of a field of this fetching row to do comparison.4 etc...Is it enough? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-18 : 04:01:51
|
quote: Post table structure, sample data and the result you want
We will be able to assist you better if we more informationalso see if this help[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57901[/url][KH] |
 |
|
|
bubix
Starting Member
24 Posts |
Posted - 2005-11-18 : 04:17:52
|
| 1. I update a value of field into several rows from Table_A IN THE SAME TIME.THis is my trigger:create trigger dbo.TableB_updateCascadeon dbo.TableAafter updateas begin --Variables qui récupèrent la (les) valeurs des tables inserted et deleted declare @vl_OldCol1 int declare @vl_NewCol1 int --Cursors for tables inserted and deleted declare cursorDeleted cursor for select Col1 from deleted declare cursorInserted cursor for select Col1 from inserted --Open cursors open cursorDeleted open cursorInserted --Extract First line fetch next from cursorDeleted into @vl_OldCol1 --Loop while (@@FETCH_STATUS = 0) begin --Extract line from table inserted fetch next from cursorInserted into @vl_NewCol1 --LOOP while (@@FETCH_STATUS=0) begin --Update table TAble_B update Table_B set Col1 = @vl_NewCol1 where TAble_B.Col1=@vl_OldCol1 end --Next line from table deleted fetch next from cursorDeleted into @vl_OldCol1 end endYou can see I have two loops because I have two cursorsHow can we do the same work but not using cursors???Thanks |
 |
|
|
bubix
Starting Member
24 Posts |
Posted - 2005-11-18 : 08:50:16
|
| I see you don't understand my sample.Finally, what I want to do, it's to perform SQL server row-by-row without cursors???? |
 |
|
|
|