I am working on Delphi7 and SQlserver 2008 R2. i have a table with some data like below.\
CREATE TABLE dbo.tstTable (
ID int IDENTITY(1,1) PRIMARY KEY,
Name varchar(255) NOT NULL,
Eid int null,
Pid int null
);
insert into tstTable(Name,Eid,Pid) values ('name1',1,null);
insert into tstTable(Name,Eid,Pid) values ('name2',2,null);
insert into tstTable(Name,Eid,Pid) values ('name3',3,null);
insert into tstTable(Name,Eid,Pid) values ('name4',null,4);
insert into tstTable(Name,Eid,Pid) values ('name5',null,5);
insert into tstTable(Name,Eid,Pid) values ('name4',null,6);
insert into tstTable(Name,Eid,Pid) values ('name7',null,null);
now i want to get the record where Eid is equal to 1. in sql server i am able to get the result.
when i try the same in delphi i am not getting any result. in Delphi, i have taken TADOConnection, TADOQuery, TDataSource and TDBGrid.
SET TADOQuery.Query = 'select Name from tstTable where Eid=:Eid and Pid =:Pid'
with ADOQuery1 do
begin
Parameters.ParamByName('Eid').Value := 1;
Parameters.ParamByName('pid').Value := NULL;//i tried with Unassigned also
Close;
open;
end; //with
when i open the AdoQuery, in grid it is not showing any records. below code is also not returning any records.
with ADOQuery1 do
begin
Parameters.ParamByName('Eid').Value := NULL;
Parameters.ParamByName('pid').Value := NULL;//i tried with Unassigned also
Close;
open;
end; //with
how to handle this scenario?

AND Pid IS NULL.NULLis not a value. It's a state of no value. - Victoriawhere something = nulljust doesn't work. OnlyISandIS NOTcan return true when comparing something with null. The other operators always return false. You say it works in SQL server, but it doesn't. You're executing a different query there, where (probably) that whole condition is omitted. - GolezTrolSET ANSI_NULLSis set toOFFin the SSMS? You could use that to use=and<>operators with null, but I don't recommend it since in a future version,ANSI_NULLSwill always beON. useIS NULLas already suggested. - kobik