Advertisement
EvgenyRudenko

Untitled

Feb 14th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. /*
  2. Тест множественной раскатки
  3. Основная процедура
  4. */
  5. CREATE OR ALTER PROCEDURE dbo.Raskatka_main
  6. @number INT
  7. WITH EXECUTE AS OWNER
  8. AS
  9.  
  10. --------------------------------------
  11. /*DECLARE
  12. @LoadSchema_int TABLE
  13. (
  14. [Schema] varchar(50) NOT NULL,
  15. [Name] VARCHAR (100) NOT NULL,
  16. [NewSchema] VARCHAR(100) NULL,
  17. [NewName] VARCHAR(100) NULL,
  18. [Params] nvarchar(4000) NULL
  19. )*/
  20. DECLARE
  21. @Schema sysname = OBJECT_SCHEMA_NAME(@@PROCID),
  22. @Name sysname = OBJECT_NAME(@@PROCID),
  23. @NewSchema sysname,
  24. @NewName sysname,
  25. @NewProcedure NVARCHAR(400),
  26. @LoadParams NVARCHAR(4000);
  27.  
  28. --INSERT INTO @LoadSchema_int([Schema], [Name], [NewSchema], [NewName], [Params])
  29. SELECT TOP 1 @Schema=[Schema], @Name= [Name], @NewSchema = [NewSchema], @NewName = [NewName], @LoadParams= [Params]
  30. FROM [Load].[Schema@Find^2]( @Schema ,@Name ,null, CAST(@number AS VARCHAR(50)))
  31. WHERE CHARINDEX( cast (@number AS VARCHAR(50)),[Params])>0;
  32.  
  33.  
  34.  
  35.  
  36. IF (@NewSchema IS NOT NULL) AND (@NewSchema <> @Schema OR @NewName <> @Name)
  37. BEGIN
  38. SET @NewProcedure = quotename(@NewSchema) + N'.' + quotename(@NewName);
  39. SELECT 'Новая процедура ',quotename(@NewSchema) + N'.' + quotename(@NewName);
  40. END
  41. ELSE
  42. SELECT 'Обычная процедура ',quotename(@NewSchema) + N'.' + quotename(@NewName);
  43.  
  44. --- тесты процедуры
  45. /*
  46. UPDATE load.[Schemas^2]
  47. SET scope = '[{"Schema": "dbo", "Name": "Raskatka_main", "NewSchema": "dbo", "NewName": "Raskatka_1", "Params":{"ShopNo":["123"]}},{"Schema": "dbo", "Name": "Raskatka_main", "NewSchema": "dbo", "NewName": "Raskatka_2", "Params":{"ShopNo":["345"]}}]' , [Values] = '123,345'
  48. WHERE [Name] = 'Raskatka_main'
  49.  
  50. EXEC raskatka_main @number = 123
  51. EXEC dbo.Raskatka_main @number = 345
  52. EXEC raskatka_main @number = 456
  53.  
  54. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement