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)
 Fetch!

Author  Topic 

diamond5
Starting Member

15 Posts

Posted - 2009-12-16 : 04:09:41
Hello ,,
plz i want the syntax,example and explain for "fetch next" it loop for select any field in tha same group > 1:N table
Thanks..

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-16 : 04:13:20
Why do you want to use a cursor?
What are you trying to do?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

diamond5
Starting Member

15 Posts

Posted - 2009-12-16 : 04:40:57
i want to read from any value of feild in the "table detail" in it related with "table master" in other words :the all of values in any master table .
thank u ser.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 04:54:37
Do you want to process data row by row???

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

diamond5
Starting Member

15 Posts

Posted - 2009-12-16 : 05:08:36
yes i want to process data row by row.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 05:12:22
Use Cursors or While loops

Does't possible by single Query!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 05:18:20
Cursors : http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/

While Loops:

declare @i int
set @i=1
while (@i<=5)
Begin
select * from (
select row_number() over(order by shortname) as s_no,* from mytable) a
where s_no=@i
set @i=@i+1
End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-16 : 05:28:35
Hi

More clear

--Table

CREATE TABLE #TBLDATA
(
ID INT IDENTITY(1,1),CODE VARCHAR(20), SOM INT, LEEN INT, HOWMUCH DECIMAL(15, 2), IMPORTDATE DATETIME
)

-- Data
INSERT INTO #TblDATA
SELECT 'XTL017X', 1123,1, 1432.99, '2009-11-30 00:00:00' UNION ALL
SELECT 'XTL017X', 112, 1, 7676.55, '2009-12-01 00:00:00' UNION ALL
SELECT 'XSDB68X', 101, 2754, 5432.56, '2009-12-01 00:00:00' UNION ALL
SELECT 'XSDB68X', 7010,3, 2754.33, '2009-11-30 00:00:00' UNION ALL
SELECT 'XSDX26X', 111, 1, 32433.11, '2009-11-30 00:00:00' UNION ALL
SELECT 'XSDX26X', 11, 3, 345676.44, '2009-12-01 00:00:00' UNION ALL
SELECT 'XEN019X', 62, 3, 543.22, '2009-12-01 00:00:00'

--QUERY

DECLARE @INT INT

SET @INT = 1

WHILE @INT <= ISNULL((SELECT COUNT(*) FROM #TblDATA),0)
BEGIN
SELECT * FROM #TblDATA WHERE ID = @INT


--- Your Data manipulations here


SET @INT = @INT + 1

END



--Drop Base Table
DROP TABLE #TBLDATA


-------------------------
R...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-16 : 05:40:40
quote:
Originally posted by diamond5

yes i want to process data row by row.


What do you do with each row?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -