Bonjour,

J'ai deux tables:

une première "section"
une seconde "livre"
chaque section contient des livres.

dans "section", il y a un attribut nbmax.

Je souhaite récupérer un nombre (nbmax) de livre par section et tiré au hasard.

Mon problème est que je reste toujours dans la même section

Merci de votre aide.

voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
DECLARE @nosection int
DECLARE @nbmax int 
DECLARE Section_Cursor CURSOR FOR
	SELECT nbmax, nosection FROM sections
 
OPEN Section_Cursor
FETCH Section_Cursor INTO @nbmax, @nosection
 
WHILE @@FETCH_STATUS = 0
	BEGIN
		SELECT TOP(@nbmax) * FROM livres where nosection = @nosection ORDER BY newid()
		FETCH NEXT FROM Section_Cursor
	END
 
CLOSE Section_Cursor
DEALLOCATE Section_Cursor