web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Find SQL View in All Microsoft Dynamics GP Databases

Ian Grieve Profile Picture Ian Grieve 22,784
Microsoft Dynamics GPI recently needed to find which databases in SQL Server had a specific view deployed to them. I’ve created scripts in the past to find SQL objects in all databases (table,trigger and functions), but not one for SQL views.

Some of the previous scripts looked in all databases and others were limited to only the Microsoft Dynamics GP databases; this script is one of the latter, using the SY015000 table to only search for a SQL view in the Dynamics GP databases:

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DECLARE @command NVARCHAR(MAX) DECLARE @SystemDatabase VARCHAR(15) = 'D20' DECLARE @View VARCHAR(50) = 'uv_AZRCRV' CREATE TABLE #ReturnedData( DBNAME VARCHAR(15) ,VIEWNAME VARCHAR(100) ) SELECT @command = 'IF EXISTS (SELECT 1 FROM sys.databases AS dbs LEFT JOIN ' + @SystemDatabase + '..SY01500 SY ON SY.INTERID = dbs.name WHERE dbs.name = ''?'' AND (dbs.name = ''' + @SystemDatabase + ''' OR SY.INTERID IS NOT NULL))
BEGIN
USE [?];
INSERT INTO #ReturnedData (dbname, VIEWNAME) (SELECT DB_NAME() AS ''DB_NAME'', o.name FROM sys.objects AS o WHERE o.type = ''V'' AND o.name LIKE '''
+ @View + '%'')
END'
EXEC sp_MSforeachdb @command SELECT * FROM #ReturnedData DROP TABLE #ReturnedData

Read original post Find SQL View in All Microsoft Dynamics GP Databases at azurecurve|Ramblings of an IT Professional


This was originally posted here.

Comments

*This post is locked for comments