Hi,
I want to search an IP address from DB. Query is like below;
select * FROM Log WHERE IP='3.3.3.3'
But I get this error,
"The data types ntext and varchar are incompatible in the equal to operator."
IP colon's format is "nText".
How may I search IP addresses?
regards.
Loading
VulpesPosted Apr 3, 2012, 4:58 AM
select * FROM Log WHERE CAST(IP as nvarchar(max)) = '3.3.3.3'
EDIT: Senthil beat me to it :)
yokzuPosted Apr 3, 2012, 6:34 AM
SenthilkumarPosted Apr 3, 2012, 5:02 AM
SenthilkumarPosted Apr 3, 2012, 4:57 AM
If you defined a column as integer then you can directly search by the value.
CREATE TABLE Example
(
ID INT IDENTITY(1,1) PRIMARY KEY,
Name Varchar(10)
}
Here the Id is integer column and name is varchar.
When you write the search ID then
SELECT * FROM Example WHERE ID=2
If you want to search the exactly name then
SELECT * FROM Example WHERE name='Senthil'
If you want to search the similar kind of names then
SELECT * FROM Example WHERE name LIKE '%Senthil%' --It will search the senthil which consist some thing like 'kumarsenthil'
SELECT * FROM Example WHERE name LIKE '%Senthil%' --It will search by name starts Senthil like 'Senthilkumar','SenthilRaja'
SELECT * FROM Example WHERE name LIKE 'Senthil%' -- It will search the name some thing like 'KumarSenthil'
I come to your example,
So we need to make both columns are equal data type to evaluate the expression.
SELECT * FROM Log WHERE CAST(IP AS nvarchar(4000))='3.3.3.3'
This will help you to fix.
If it is useful then mark it as "Correct Answer"
yokzuPosted Apr 3, 2012, 4:50 AM
"SELECT * FROM Log WHERE IP=CAST('"+TextBox3.Text.ToString()+"' as ntext)";
But I get this error; The data types ntext and ntext are incompatible in the equal to operator.
VulpesPosted Apr 3, 2012, 4:44 AM