Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Locate a column across databases


Locate a column across databases

Author
Message
Douglas Osborne-229812
Douglas Osborne-229812
SSC-Enthusiastic
SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)

Group: General Forum Members
Points: 125 Visits: 358
Comments posted to this topic are about the item Locate a column across databases
mlfrench
mlfrench
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 21
Hello,
Getting error: Database 'SWS' does not exist. Make sure that the name is entered correctly.



I copied the script from the article for MASTER.dbo.LocateColumnDefinations

When I execute the following:
EXEC [dbo].[LocateColumnDefinitions]
@Column = '%PONO%',
@Branch = NULL,
@DB = 'TritonIND',
@ViewTableAll = NULL
I get an error:
Msg 911, Level 16, State 1, Line 2
Database 'SWS' does not exist. Make sure that the name is entered correctly.

When I ran the generated sql:
IF DB_NAME() = 'TritonIND' AND EXISTS
(
SELECT 1
FROM sys.columns AS SC
INNER JOIN sys.objects AS SO ON SC.OBJECT_ID = SO.OBJECT_ID
INNER JOIN sys.types AS ST ON SC.system_type_id = ST.system_type_id AND NOT (ST.system_type_id = 231 AND ST.name = 'nvarchar')
WHERE SC.Name Like '%PONO%' AND SO.Type_Desc = 'User_Table'
)
BEGIN
SELECT DB_NAME() AS [Database], OBJECT_NAME( SC.OBJECT_ID ) AS [Table], SC.name AS [Column], CASE SO.Type_Desc WHEN 'User_Table' THEN 'Table' ELSE 'View' END AS [Object Type],
CASE ST.Name
WHEN 'VARCHAR' THEN 'VARCHAR(' + CAST( SC.Max_Length AS VARCHAR ) + ')'
WHEN 'NVARCHAR' THEN 'NVARCHAR(' + CAST( SC.Max_Length AS VARCHAR ) + ')'
WHEN 'CHAR' THEN 'CHAR(' + CAST( SC.Max_Length AS VARCHAR ) + ')'
WHEN 'NCHAR' THEN 'NCHAR(' + CAST( SC.Max_Length AS VARCHAR ) + ')'
WHEN 'INT' THEN 'INT'
WHEN 'BIT' THEN 'BIT'
WHEN 'BIGINT' THEN 'BIGINT'
WHEN 'SYSNAME' THEN 'SYSNAME'
WHEN 'DATETIME' THEN 'DATETIME'
WHEN 'FLOAT' THEN 'FLOAT'
WHEN 'DATE' THEN 'DATE'
WHEN 'DECIMAL' THEN 'DECIMAL(' + CAST( SC.Precision AS VARCHAR ) + ', ' + CAST( SC.Scale AS VARCHAR) + ')'
WHEN 'TIMESTAMP' THEN 'TIMESTAMP'
ELSE ST.Name
END AS Type
, CASE SC.Is_NULLable WHEN 1 THEN 'NULL' ELSE 'NOT NULL' END AS Nullable,
ISNULL( object_definition( SC.default_object_id ), '' ) AS [Default]
FROM sys.columns AS SC
INNER JOIN sys.types AS ST ON SC.system_type_id = ST.system_type_id AND NOT (ST.system_type_id = 231 AND ST.name = 'nvarchar')
INNER JOIN sys.objects AS SO ON SC.OBJECT_ID = SO.OBJECT_ID
INNER JOIN sys.all_objects AS AO ON SC.OBJECT_ID = AO.OBJECT_ID
WHERE SC.Name Like '%PONO%' AND SO.Type_Desc = 'User_Table'
ORDER BY SO.[Type_Desc], OBJECT_NAME( SC.OBJECT_ID )
END

I retrieved the following results:

Database Table Column Object Type Type Nullable Default
TritonIND AROpenInvoiceHeader_ACCINVHD ARPONO Table CHAR(16) NOT NULL
TritonIND CreditDebitInvoiceHeader_CRDINVHD OHPONO Table CHAR(16) NOT NULL
TritonIND DailySalesHeader_ORDDLYHD OHPONO Table CHAR(16) NOT NULL
TritonIND DiscountPlanColumn_PRCDSPLC PPONOF Table CHAR(1) NOT NULL
TritonIND ItemPriceAll_IND517B99P APONOF Table CHAR(1) NOT NULL
TritonIND OrderEntryHeader_ORDENTHD OHPONO Table CHAR(16) NOT NULL
TritonIND PickupMemoHeader_ORDPUMHD OHPONO Table CHAR(16) NOT NULL
TritonIND PromotionComboListInventory IPONOR Table DECIMAL(9, 2) NOT NULL
TritonIND SpecialDiscountProfileHeader_PRCDSCPR SPONOF Table SYSNAME NOT NULL
TritonIND TopazInterfaceHeader_XR200P XHPONO Table CHAR(22) NOT NULL
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9768 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search