Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2003, 07:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Maybe something like this?:

Code:
DROP TABLE #tbTempTable
CREATE TABLE #tbTempTable (TableName NVARCHAR(1000), TheCount INT)

Declare MyCursor CURSOR
GLOBAL
SCROLL
KEYSET
FOR
SELECT SO.[name] AS TABLENAME, SC.[name] AS COLUMNNAME
FROM sysobjects SO
LEFT JOIN syscolumns SC ON SO.id=SC.id
WHERE SO.xtype = 'U' 
ORDER BY SO.[name], SC.[name]

DECLARE @TableName nvarchar(100)
DECLARE @ColumnName nvarchar(100)
DECLARE @SQLString nvarchar(1000)
DECLARE @INITCount int

OPEN MyCursor

Fetch next from MyCursor INTO @TableName, @ColumnName

while @@fetch_status=0
Begin
--    Set @SQLString = 'SELECT ''' + @TableName + ''', Count(*) FROM ' + @TableName + ' WHERE ' +  @ColumnName + ' LIKE ''%Tester%'''
    Set @SQLString = 'INSERT INTO #tbTempTable (TableName, TheCount) SELECT ''' + @TableName + ''' AS TableName, Count(*) AS TheCount FROM ' + @TableName
    EXEC sp_executesql @SQLString
    Fetch next from MyCursor INTO @TableName, @ColumnName
End

close MyCursor
deallocate MyCursor

SELECT * FROM #tbTempTable WHERE TheCount > 0
/*
OR MAYBE:
SELECT DISTINCT * FROM #tbTempTable WHERE TheCount > 0
*/
 
Old December 3rd, 2003, 02:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Is this issue resolved?






Similar Threads
Thread Thread Starter Forum Replies Last Post
String Manipulation Question JMOdom C# 0 April 10th, 2007 11:38 AM
connection string question -Dman100- SQL Server ASP 7 August 17th, 2004 04:10 PM
Number String Question CNewbie C++ Programming 28 April 1st, 2004 07:59 PM
String in mc++ question Ereinion Visual C++ 0 November 7th, 2003 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.