Avatar of srk1982
srk1982

asked on 

Search for a column name in sql server 2005 database using Store Proc.

Hi,

I want to write a stored procedure where the input parameter
will be the text. Now, i want to search for that similar column name
in the database and it shud return me the column name and Table name.
Please help me on this,
Its urgent.
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Bretty1
Avatar of ofkr
ofkr
Flag of Singapore image

SELECT COLUMN_NAME, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME =  'COLUMNSEARCH'
ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of elimesika
elimesika
Flag of Israel image

HI

See code
CREATE PROCEDURE [dbo].[Find_Columns]
	 @name nvarchar(128)
AS
BEGIN
 
select t.name as [Table Name] , c.name as [Column Name]
from sys.tables t, sys.columns c
where t.[object_id] = c.[object_id]
and c.name = @name
 
END

Open in new window

Avatar of Bretty1
Bretty1
Flag of Australia image

Try this:
Pocedure:
Use [databasename]
Create Procedure [dbo].[FindDatabaseColumns]
@Column_Name NVarChar(128)
AS
SELECT *
FROM information_schema.columns
WHERE column_name LIKE '%' +  @Column_Name + '%'
go
Script query:
Use [databasename]

SELECT *
FROM information_schema.columns
WHERE column_name LIKE '%datatablename%'
go
Bretty
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo