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
 Old Forums
 CLOSED - General SQL Server
 pass a cursore value to variable

Author  Topic 

casati74
Posting Yak Master

109 Posts

Posted - 2006-08-25 : 04:15:54
Hello,
I must assign a cursore value to a varible, how can i do it????

I have

DECLARE @nometabella nvarchar(100)
DECLARE miocursore CURSOR FOR
SELECT valore FROM #miatmp
OPEN miocursore



-- Perform the first fetch.
FETCH NEXT FROM miocursore

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS <>-1
BEGIN
select @nometabella = miocursore ***** This is a problem

print @nometabella

FETCH NEXT FROM miocursore
END

CLOSE miocursore
DEALLOCATE miocursore
GO

How can i assigna to @nometabella a miocursore.value????

Thank's

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-25 : 04:20:13
[code]DECLARE @nometabella nvarchar(100)
DECLARE miocursore CURSOR FOR
SELECT valore FROM #miatmp
OPEN miocursore



-- Perform the first fetch.
FETCH NEXT FROM miocursore INTO @NomeTabella

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS <>-1
BEGIN
--select @nometabella = miocursore ***** This is a problem

print @nometabella

FETCH NEXT FROM miocursore INTO @NomeTabella
END

CLOSE miocursore
DEALLOCATE miocursore
GO[/code]Also read about CURSORS in Books Online.

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

casati74
Posting Yak Master

109 Posts

Posted - 2006-08-25 : 04:41:40
I have tried but making therefore forehead of every line me of it, it inserts 30 equal ones why?

ex:
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822
Samples
SampleID
9822

but if exec a select where id = 9822 i recive only one row


Samples 9822 I 2006-08-05 06:08:01.093

Why????

Thank's a lot
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-25 : 04:43:55
I can't tell since I don't know the insert statement.

Try to use
DECLARE miocursore CURSOR FOR
SELECT DISTINCT valore FROM #miatmp
or
DECLARE miocursore CURSOR FOR
SELECT valore FROM #miatmp where id = 9822

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-25 : 04:46:01
I think the data in temporary table #miatmp is the problem.
write
select * from #miatmp
to see if the data is duplicated there.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

casati74
Posting Yak Master

109 Posts

Posted - 2006-08-25 : 04:47:01
thank's a lot a solv after send a new topic!!!!


Thank's!!!!
Go to Top of Page
   

- Advertisement -