Bonjour j'essaye de faire une procédure stockée avec un bête switch mais j'ai des erreurs de syntaxe
Pourriez-vous m'aider
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
ALTER FUNCTION [dbo].[GetProductContractSeqNr]
(
@TableName as varchar(128)
@Id as int
)
RETURNS int
AS
BEGIN
	DECLARE @ProductContractSeqNr as int 
	DECLARE @SQL as varchar(8000)	
	SET @ProductContractSeqNr=NULL	
 
	SET @SQL='Select @ProductContractSeqNr=ProductContractSeqNr '
	SET @SQL=@SQL+'From dbo.[@Table] '
 
	CASE @TableName
	WHEN 'Toto' THEN
		SET @SQL=@SQL+' Where Id=' + @ID
	WHEN 'Tata' THEN
		SET @SQL=@SQL+' Where Tata_Id=' + @ID
	END CASE		
	EXEC (@SQL) 
	RETURN @ProductContractSeqNr
END
Merci