如何在SQL Server中添加一个变量来替换%MV_AUG2019.json%
,以便我只需要在所有这些表中更改它?
delete from [addresses] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [disabilities] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [MD] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [messages] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [MH] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [MV] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [permits] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [PP] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [registrationOwners] where [uniqueFilename] like '%MV_AUG2019.json%'
delete from [stops] where [uniqueFilename] like '%MV_AUG2019.json%'
我敢打赌你只是在 ->
之后DECLARE @FileName NVARCHAR(500) = 'MV_AUG2019.json'
delete from [addresses] where [uniqueFilename] like '%'+@FileName+'%'
您必须在下面声明一个变量:
DECLARE @var NVARCHAR(1000) = 'name.json' -- provide file name here
delete from [addresses] where [uniqueFilename] like '%' + @var + '%'
您可以在Dynamic
中生成表DECLARE @FileName NVARCHAR(500) = 'MV_AUG2019.json'
SELECT 'DELETE FROM '+QUOTENAME(TABLE_NAME) +' WHERE '+ QUOTENAME(COLUMN_NAME)+ ' LIKE '+'''%'+ @FileName+'%'''
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME ='uniqueFilename' AND DATA_TYPE IN ('char','nvarchar','varchar')