Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare two databases

Status
Not open for further replies.
Dec 31, 2004
71
GB
Hi All,
I'm trying to compare data in two databases for all tables, I found the below code which works OK but does not work for text, ntext columns

Below is the code im using

set @SQL = 'SELECT ''' + @table1 + ''' AS TableName, ' + @t1ColumnList +
' FROM ' + @Table1 + ' UNION ALL SELECT ''' + @table2 + ''' As TableName, ' +
@t2ColumnList + ' FROM ' + @Table2

set @SQL = 'SELECT Max(TableName) as TableName, ' + @t1ColumnList +
' FROM (' + @SQL + ') A GROUP BY ' + @t1ColumnList +
' HAVING COUNT(*) = 1'

Is there a way of using UNION ALL with text, ntext ?

Thanks
Nathan

 
If you're using SQL Server 2005 and up try casing text to varchar(max) and ntext to nvarchar(max).

In SQL Server 2000 you may try using substring(text,1,8000) and substring(ntext,1,4000) - so it will be good for that number of characters.

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top