저는 Delphi7 및 SQlserver 2008 R2에서 작업 중입니다. 나는 아래와 같은 일부 데이터가있는 테이블이 있습니다. \TADOQuery : 매개 변수로 null 전달 및 결과 집합 얻기
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);
지금 내가 이드 내가 결과를 얻을 수 있어요 SQL 서버 1. 동일 기록을 싶어.
는 내가 어떤 결과를 얻고 있지 않다 델파이에서 동일 할 때. 델파이에서 , 나는 TADOConnection, TADOQuery, TDataSource 및 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
AdoQuery를 열면 그리드에 레코드가 표시되지 않습니다. 코드 아래의 도 레코드를 반환하지 않습니다.
with ADOQuery1 do
begin
Parameters.ParamByName('Eid').Value := NULL;
Parameters.ParamByName('pid').Value := NULL;//i tried with Unassigned also
Close;
open;
end; //with
이 시나리오를 처리하는 방법은 무엇입니까?
'AND Pid IS NULL'을 사용하십시오. 'NULL'은 값이 아닙니다. 그것은 가치가없는 상태입니다. – Victoria
@ 빅토리아 : 나는 그것을 시도했다. 모든 매개 변수를 전달하려고 할 때 실패합니다 null입니다. 우리가 "tstTable (Name, Eid, Pid) 값 ('name7', null, null)에 삽입하는 것과 같은 레코드를 가지고있을 때; – DelphiLearner
'where something = null'은 작동하지 않습니다. 'IS'와'IS NOT'만이 무언가를 null과 비교할 때 true를 반환 할 수 있습니다. 다른 연산자는 항상 false를 반환합니다. 당신은 SQL 서버에서 작동한다고 말하지만, 그렇지 않습니다. 거기에서 다른 쿼리를 실행하고 있습니다. 아마도 전체 조건이 생략되었을 것입니다. – GolezTrol