sql server 2012 - Distinct error with image field -


i have table contains image column. want select distinct value of image column, gives error. column name image.

my query is: select image tbl1

error is: image data type cannot selected distinct because not comparable.

so how select distinct value tb1 table

image data types in select statement contains distinct clause. depending on version of sql server being used, there few ways of overcoming restriction.

for sql server 2000, text column can converted varchar data type, ntext column can converted nvarchar data type while image data type can converted varbinary data type. select statements earlier contain distinct clause can rewritten follows , avoid error message:

select distinct [booktitle], cast([booksummary] nvarchar(4000)) [booksummary] [dbo].[book]

select distinct [booktitle], cast([bookimage] varbinary(8000)) [bookimage] [dbo].[book] sql server 2005 , sql server 2008 (and later), instead of limiting nvarchar 4000 characters or varchar or varbinary 8000 characters, max specifier can used in place, can seen in following select statements:

select distinct [booktitle], cast([booksummary] nvarchar(max)) [booksummary] [dbo].[book]

select distinct [booktitle], cast([bookimage] varbinary(max)) [bookimage] [dbo].[book] if using sql server 2005 or sql server 2008 (or later), way of overcoming restriction , error message without using cast or convert function convert text, ntext , image data types varchar, nvarchar , varbinary, respectively, change data types of columns varchar(max), nvarchar(max) , varbinary(max). text, ntext , image data types removed in future version of microsoft sql server , use of these data types should avoided.

reference: http://www.sql-server-helper.com/error-messages/msg-421.aspx


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -