In my SQL, I would need to compare data between two tables in SQLServer 2008R2 to return the rows where mismatch is present (using EXCEPT
) and likewise matching rows in other cases (INTERSECT
). The problem is, some of the columns have NTEXT
datatype (SQLServer), and SQLServer gives error when such tables having columns with NTEXT
are present.
Example:
SELECT * FROM table_pre
EXCEPT
SELECT * FROM table_post
The above operation gives an error -
'The ntext data type cannot be selected as DISTINCT because it is not comparable.'
I believe that tables (table_pre
, table_post
) have at least one column of datatype = NTEXT
that is causing the comparison to fail.
Question -
1. Is there some way to exclude these NTEXT
columns from the above comparison, without me having to explicitly list out the column names and excluding the problem column? There's a large number of columns involved and explicitly listing is not easy.
2. Can I just explicitly cast/convert the NTEXT
column alone to say VARCHAR
, and still go by not having to list down the rest of the columns?
3. Or, in general, can I somehow exclude certain columns by listing those out during such comparisons?
Any suggestions, really appreciated! Thanks.