Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
hi all,

i've a Image column and wanted to check whether it is empty in StoredProc.And i also tried like this,if(@Imag=Null),but showing error like
The text, ntext, and image data types cannot be compared or sorted.please reply with an example
Posted
Updated 9-Aug-20 2:46am
Comments
pankajupadhyay29 7-Mar-11 0:10am    
i think if(@Imag is Null) will work

check if image column is null then DataLength() will be zero
select DataLength(column1) from table1


see here[^]
 
Share this answer
 
Comments
ks ravi 7-Mar-11 0:20am    
please explore your explanation, i'm not getting it
m@dhu 7-Mar-11 0:32am    
DataLenth() Returns the number of bytes. If the image column will be empty then DataLength(your image column) will return 0.
Try out this for better understanding.

SQL
DECLARE @Img varchar(50)
SET @Img = (SELECT ImageName FROM MyTable WHERE Id=1)

IF @Img IS NULL
    BEGIN
        PRINT 'Image is NULL'
    END
ELSE IF LEN(@Img) < 0
    BEGIN
        PRINT 'Image is blank'
    END
ELSE
    BEGIN
        PRINT 'Image is available = ' + @Img
    END


Hope it helps.
 
Share this answer
 
Try this...
Declare int column_length;
declare curs cursor for select Length(image) from user_table where user_name ="XXX";

open curs
fetch curs into column_length
close curs

Hope this will help...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900