Procedure stocké

bialain Messages postés 11 Date d'inscription mardi 27 avril 2010 Statut Membre Dernière intervention 23 mars 2011 - 12 sept. 2010 à 10:40
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 - 12 sept. 2010 à 23:25
Bonjour mes amis.
j'ai un problème de limiter les enregistrements et je veux qlq'un pour m'aider.
En effet, j'ai créé un procedurre stocké comme suit:

ALTER PROCEDURE [dbo].[Ps_OrientationSection]
@SectionAuto int

AS

insert into TabOrientation(EtabliOrigineAuto,EleveAuto,SectionAuto)
(select EtabliOrigineAuto,EleveAuto,Choix1 from View_choix_1 where Choix1= @SectionAuto and EleveAuto NOT IN (SELECT EleveAuto FROM TabOrientation))

Jusqu'ici, pas de problèmes. Mais quand je veux limiter les lignes en utilisant " Top ", il y a un message d'erreur qui s'affiche. voici comment j'ai fait:

ALTER PROCEDURE [dbo].[Ps_OrientationSection]
@NTop int,
@SectionAuto int

AS

insert into TabOrientation(EtabliOrigineAuto,EleveAuto,SectionAuto)
(select top @NTop EtabliOrigineAuto,EleveAuto,Choix1 from View_choix_1 where Choix1 =@SectionAuto and EleveAuto NOT IN (SELECT EleveAuto FROM TabOrientation))

Le message d'erreur est :

Msg 102, Level 15, State 1, Procedure Ps_OrientationSection, Line 18
Incorrect syntax near '@NTop'.
Msg 102, Level 15, State 1, Procedure Ps_OrientationSection, Line 18
Incorrect syntax near ')'.

Où est que je me suis trompé? J'utilise le SqlServer.

Je vous remercie

2 réponses

foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
12 sept. 2010 à 23:24
Bonjour,

Top combien ? Il faut lui préciser le nombre :

SELECT TOP(2) ColumnA
FROM Table1
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
12 sept. 2010 à 23:25
Pardon, j'ai répondu trop vite, il vous manque juste les parenthèses :

insert into TabOrientation(EtabliOrigineAuto,EleveAuto,SectionAuto)
(
select top(@NTop) EtabliOrigineAuto,EleveAuto,Choix1
from View_choix_1
where Choix1=@SectionAuto
and EleveAuto NOT IN (SELECT EleveAuto FROM TabOrientation))
0
Rejoignez-nous