bonjour a tous,j ai un serieux probleme en sql qui me casse la tete de puis longtemps. il est le suivant:
je dois ecrire une procedure qui copie entierement les donnees et la syntaxe d une table dans une autre table. cette procedure doit prendre en entree les noms des 2 tables. voici mon code si ca peut vous aider
mais j ai les erreurs du genre
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 -- Verify that the stored procedure does not exist. IF OBJECT_ID ('usp_GetErrorInfo', 'P') IS NOT NULL DROP PROCEDURE usp_GetErrorInfo; GO -- Create procedure to retrieve error information. Create PROCEDURE usp_GetErrorInfo AS SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() as ErrorState, ERROR_PROCEDURE() as ErrorProcedure, ERROR_LINE() as ErrorLine, ERROR_MESSAGE() as ErrorMessage; GO CREATE PROCEDURE COPIE_table @source varchar(50), @destination varchar (50) as begin try if NOT EXISTS (Select * from sysobjects where name = @source and Xtype='U' )--Permet de savoir si une table 'source' existe dans notre base de données BEGIN print 'table source pas dispo' END else BEGIN if NOT EXISTS(Select * from sysobjects where name= @destination and Xtype='U' ) BEGIN select * into @destination from @source print 'copie reussie' END else BEGIN if exists (select * from @destination) BEGIN delete from @destination select * into @destination from @source print 'copie reussie' END else BEGIN select * into @destination from @source print 'copie reussie' END END end try begin catch execute usp_GetErrorInfo end catch GO
s il vous plait aidez moi, je suis la dessus depuis tres longtempsMsg 102, Level 15, State 1, Procedure COPIE_table, Line 15
Incorrect syntax near '@destination'.
Msg 1087, Level 15, State 2, Procedure COPIE_table, Line 21
Must declare the table variable "@destination".
Msg 1087, Level 15, State 2, Procedure COPIE_table, Line 23
Must declare the table variable "@destination".
Msg 102, Level 15, State 1, Procedure COPIE_table, Line 24
Incorrect syntax near '@destination'.
Msg 156, Level 15, State 1, Procedure COPIE_table, Line 27
Incorrect syntax near the keyword 'else'.
Msg 102, Level 15, State 1, Procedure COPIE_table, Line 29
Incorrect syntax near '@destination'.
Msg 102, Level 15, State 1, Procedure COPIE_table, Line 35
Incorrect syntax near 'begin'.
merci de votre aide
Partager