Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HEllo team,

I want to select the null value or empty value from Database.
All columns are varchar.
SQL
select ID,FULLADDRESS,CUSTOMERADDR1,CUSTOMERADDR2,LANDMARK,CITY,STATE, PINCODE from customerloandata
with (nolock) where isnull(city,0)= 0 or isnull(STATE,0)= 0 or isnull(PINCODE,0)= 0


I am getting the following error.

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'Warangal' to data type int.

How to solve it?
Please help

Thanks
Harshal.
Posted

1 solution

You are returning two different types of data: VARCHAR and INT - so SQL tries to be helpful and automatically parse the VARCHAR as an INT for you. Since it contains text that isn;t a number, it fails.
Instead, try this:
SQL
select ID,FULLADDRESS,CUSTOMERADDR1,CUSTOMERADDR2,LANDMARK,CITY,STATE, PINCODE from customerloandata
with (nolock) where city IS NULL or STATE IS NULL or PINCODE IS NULL


[edit]Forgot the code block :doh: - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
[no name] 12-Feb-14 7:31am    
Thank you for your answer.Error was solved .
But i am not getting the record.I have one record in which city and pincode are blank.I want to get that record .But its not happening .Why is it so?
Kindly help.
OriginalGriff 12-Feb-14 7:40am    
"Blank" is not the same as NULL - have you checked for empty strings?
[no name] 12-Feb-14 7:45am    
I got it Boss.Thank you.
OriginalGriff 12-Feb-14 8:28am    
You're welcome!

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