Skip to main content

Search specific string inside Stored Procedure, View, Function, Trigger, Table Name, Table Field in SQL Server

this query can be used to search specific string inside, no need to right click  - modify - and search manually from Query designer / SSMS


DECLARE @NextString NVARCHAR(40)
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @String NVARCHAR(40)
DECLARE @Delimiter NVARCHAR(40)
DECLARE @Query nvarchar(2000)
DECLARE @WHERE nvarchar(1000)

DECLARE @Query2 nvarchar(2000)
DECLARE @Where2 nvarchar(1000)

SET @Query =
 'SELECT DISTINCT so.name, ' +
   'CASE so.xtype ' +
    'WHEN ''P'' THEN ''SPROC'' ' +
    'WHEN ''IF'' THEN ''FUNCTION'' ' +
    'WHEN ''FN'' THEN ''FUNCTION'' ' +
    'WHEN ''V'' THEN ''VIEW'' ' +
    'WHEN ''U'' THEN ''TABLE'' ' +
    'WHEN ''TR'' THEN ''TRIGGER'' ' +
   'END AS [TYPE] ' +
 'FROM syscomments sc ' +
   'RIGHT JOIN sysobjects so ON sc.id = so.id ' +
 'WHERE '
SET @String = 'cab'
SET @WHERE = ''
SET @Where2 = ''
SET @Delimiter = ','
SET @String = 'cab' + @Delimiter
SET @Pos = CHARINDEX(@Delimiter,@String)

WHILE (@pos <> 0)
BEGIN
 SET @NextString = LTRIM(RTRIM(SUBSTRING(@String, 1, @Pos - 1)))
 PRINT 'next: ' + @NextString

IF LEN(@WHERE) > 0
BEGIN
SET @WHERE = @WHERE + ' OR sc.[TEXT] LIKE ''%' + @NextString + '%''' +
' OR so.[name] LIKE ''%' + @NextString + '%'''

print '42: ' + @where2
SET @Where2 = @where2 + ' OR T0.Name LIKE ''%' + @NextString + '%'' '
print '42: ' + @where2
END
ELSE
BEGIN
SET @WHERE = @WHERE + ' sc.[TEXT] LIKE ''%' + @NextString + '%''' +
' OR so.[name] LIKE ''%' + @NextString + '%'''

print '51: ' + @where2
SET @Where2 = @Where2 + ' t0.Name LIKE ''%' + @NextString + '%'' '
print '51: ' + @where2
END

 SET @String = SUBSTRING(@String, @pos + 1, LEN(@String))
 SET @pos = CHARINDEX(@Delimiter, @String)
END

SET @WHERE = 'so.xtype IN (''P'', ''IF'', ''FN'', ''V'', ''U'', ''TR'') AND (' + @WHERE + ')'

SET @Query2 =
 'UNION ALL ' +
 'SELECT t1.NAME, ''TABLE FIELD'' AS [TYPE] ' +
 'FROM syscolumns t0 ' +
  'INNER JOIN sysobjects t1 ON t0.ID = t1.ID ' +
 'WHERE '
SELECT @Where2 = 't1.xType = ''U'' ' +
CASE WHEN LEN(@Where2) > 0 THEN ' AND (' + @Where2 + ')' ELSE '' END

PRINT @Query + @WHERE + @Query2 + @Where2
EXEC (@Query + @WHERE + @Query2 + @Where2)
until then

Comments

Popular posts from this blog

Crystal Report 2010 - Failed to load database information

"Failed to load database information" error when i try deploy my program with CR 2010 using TTX file as report definition this is because there is missing .dll, call "CRDB_FIELDDEF.DLL"..u need to manually copy the file to "C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86" folder then the report is loading again it said that TTX is old tech but i'm still using it because i don't need to connect the report to any DB, but until i found new one to replace :D check this link to read it [EDIT 25 Jan 2011] i think i'll using ADO.NET Dataset next time :D until then

Could not load file or assembly error in VS 2010 and CR

when u received this kind of error "Could not load file or assembly 'file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified." try to add this to your .config file (usually app.config) PS: don't forget to remove extra space after " see u

SBO - Internal Error (-5002) Occured in Inventory Transfer

this is something that not well documented in SBO, it took me several hours to look at Google and can't find anything about it. Thank God friend of mine got answer for this one.So the Sympton is something like this, u need to make Inventory Transfer for Batch Item and Serial Item in one single Transaction so the Transaction is the combination of it. ex in detail lines: 1. Serial Item 2. Batch Item 3. Batch Item 4. Batch Item 5. Serial Item 6. Serial Item . When u reach this code oStockTransfer.Add it will return an error "Internal Error (-5002) Occured". This is because ur details is not in order, meaning u need to order the line with combination of Batch first then Serial or Serial first then Batch so be careful with this thing :D see u