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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
DECLARE @Statement NVARCHAR(MAX)
DECLARE @VarStatement NVARCHAR(MAX)
SET @Statement =
N'
CREATE SYNONYM dbo.SYNV FOR {name}.[dbo].[ISSCompetitionsPlayers]
GO
ALTER VIEW SYNV
AS
SELECT
M.Id AS Id
, LHCP.Handicap AS Hcp
, M.Lname AS Lname
, M.Fname AS Fname
, M.MFname AS MFname
, M.birthdate AS birthdate
, CM.Status AS Status
, M.FederalNumber AS fedNum
, CM.IdClub AS clubID
, C.id AS compID
FROM MyGolf.dbo.tMembers AS M
INNER JOIN MyGolf.dbo.tClubMembers AS CM ON (
CM.IdMember = M.Id
)
LEFT JOIN MyGolf.dbo.tLastHandicaps AS LHCP ON (
LHCP.idmember = M.Id
)
CROSS JOIN {name}.dbo.Competitions AS C
WHERE M.FederalNumber <> ''''
AND EXISTS (
SELECT TOP(1)
1
FROM {name}.dbo.vMembersCategory AS CAT
WHERE CAT.memberID = M.Id
AND CAT.Type = ''Tee''
AND CAT.compID = C.id
AND (C.locked = 0 OR CAT.IsExactMatch = 1)
)
GO
DROP SYNONYM SYNV
GO
'
DECLARE cur CURSOR FOR
SELECT DBName
FROM tManagement_Websites
INNER JOIN sys.databases AS DB ON (
DB.name = tManagement_Websites.DBName COLLATE FRENCH_CI_AS
)
DECLARE @DBName VARCHAR(50)
OPEN cur
FETCH NEXT FROM cur INTO @DBName
WHILE(@@FETCH_STATUS = 0)
BEGIN
SET @VarStatement = REPLACE(@Statement, '{name}', @DBName)
EXECUTE sp_executesql @VarStatement
FETCH NEXT FROM cur INTO @DBName
END
CLOSE cur
DEALLOCATE cur |
Partager