|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
HI ALL,
As i Have a task to find 9 digit value in all column of all table in a DB or All DB in SQL server 2005.
SO DO ANY ONE HAVE THE T-SQL STATEMENT TO FIND IT?
All Help is appreciated.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Sunday, December 09, 2012 11:47 PM
Points: 60,
Visits: 169
|
|
Ivan Mohapatra (1/9/2012) HI ALL,
As i Have a task to find 9 digit value in all column of all table in a DB or All DB in SQL server 2005.
SO DO ANY ONE HAVE THE T-SQL STATEMENT TO FIND IT?
All Help is appreciated.
You'll need to use dynamic SQL to query for the character columns, then in a cursor loop through those columns looking for the correct values.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
| hi u mean by using DMV query can u just Send me the query so that i can go through it and find the query
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:01 AM
Points: 38,
Visits: 140
|
|
hi you may use the Len variable.
select employeeID, EmployeeName, EmployeeTask from Employees where Len(employeedID) = 9
this will post only all employeeID whos lenght is 9 eg.(000333444)
hope this helps :)
cheers!
===============================================================
"lets do amazing" our company motto..
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:01 AM
Points: 38,
Visits: 140
|
|
in addition you may use this script.. :)
you may want to run this per database lol.. haha just change the value to what you want to search lol.. you get the idea? just tweek it some more and you might be able to modify it to the one you need. this will return the table where it was located.
EXEC SearchAllTables 'Computer'
CREATE PROC SearchAllTables ( @SearchStr nvarchar(100) ) AS BEGIN
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110) SET @TableName = '' SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @TableName IS NOT NULL BEGIN SET @ColumnName = '' SET @TableName = ( SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName AND OBJECTPROPERTY( OBJECT_ID( QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) ), 'IsMSShipped' ) = 0 )
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL) BEGIN SET @ColumnName = ( SELECT MIN(QUOTENAME(COLUMN_NAME)) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2) AND TABLE_NAME = PARSENAME(@TableName, 1) AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar') AND QUOTENAME(COLUMN_NAME) > @ColumnName ) IF @ColumnName IS NOT NULL BEGIN INSERT INTO #Results EXEC ( 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @TableName + ' (NOLOCK) ' + ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2 ) END END END
SELECT ColumnName, ColumnValue FROM #Results END
===============================================================
"lets do amazing" our company motto..
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
i don'nt know the table & column i just want to find table name and column name where data len = 9
can any one ping the script PLZ
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
| i don't know the table name and column name So this query will not match my requirement.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
mrdenny can u send me the script
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 10:26 PM
Points: 8,606,
Visits: 8,247
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:59 AM
Points: 104,
Visits: 362
|
|
yes exactly i want all the column name and table name where value is 9 character
|
|
|
|