Hello All,
I needed help with the below query. I was trying to create a parameterized proc that takes Server Name, DB Name and Table Name and returns metadata from information_schema.columns.
Thanks for your support!
CREATE PROC GetMetadata @ServerName varchar(25), @DbName varchar(25), @TableName varchar(25)
AS
SET NOCOUNT ON;
SET @ServerName = (
SELECT NAME FROM sys.servers
WHERE server_id = 0
);
SET @DbName = (
SELECT NAME FROM sys.databases
);
SELECT TABLE_NAME,
COLUMN_NAME,
DATA_TYPE
FROM [@ServerName].[@DbName].INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = @DbName AND
TABLE_NAME = @TableName
EXEC GetMetadata '@ServerName', '@DbName', '@TableName'