zetoune | CREATE PROC SP_SearchAndReplace
(
@SearchStr nvarchar(100),
@ReplaceStr nvarchar(100),
@NomTable nvarchar(100),
@NomColonne nvarchar(100),
@Id_Site bigint
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110), @SQL nvarchar(4000), @RCTR int
SET @TableName = @NomTable
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
SET @RCTR = 0
SET @ColumnName = @NomColonne
BEGIN
SET @SQL= 'UPDATE ' + @TableName + ' SET ' + @ColumnName + ' = REPLACE(' + @ColumnName + ', ' + QUOTENAME(@SearchStr, '''') + ', ' + QUOTENAME(@ReplaceStr, '''') + ') WHERE Id_Site=' + @Id_Site + ' AND ' + @ColumnName + ' LIKE ' + @SearchStr2 EXEC (@SQL)
END
END
GO |
J'ai corrigé ma procédure comme suit et ca , ca fonctionne..
mais je trouve ca un peu barbare..
CREATE PROC SP_SearchAndReplace
(
@SearchStr nvarchar(100),
@ReplaceStr nvarchar(100),
@NomTable nvarchar(100),
@NomColonne nvarchar(100),
@Id_Site bigint
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110), @SQL nvarchar(4000), @RCTR int
SET @TableName = @NomTable
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
SET @RCTR = 0
SET @ColumnName = @NomColonne
BEGIN
SET @SQL= 'UPDATE ' + @TableName + ' SET ' + @ColumnName + ' = REPLACE(' + @ColumnName + ', ' + QUOTENAME(@SearchStr, '''') + ', ' + QUOTENAME(@ReplaceStr, '''') + ') WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2 EXEC (@SQL + ' AND ID_Site=' + @Id_Site)
END
END
GO |
|