PDA

View Full Version : اتصال جداول



DlphIran
دوشنبه 06 مهر 1388, 19:15 عصر
سلام ،‌من در برنامه كتابداريم ،‌ يه جدول اطلاعات كتاب دارم و يه جدول امانت

مي خوام بعد از جستجو روي جدول امانت ،‌حاصل جستجو اتصال پيدا كنه به جدول كتابها و ريز اطلاعات كتابهاي امانت داده شده رو به كاربر نشون بده .

تا اينجا مشكلي ندارم ،‌اما در خروجي اگر كتابي سه بار امانت داده شده باشه در جدول اطلاعات كتاب بجاي اينكه يكبار مشخصات اين كتاب رو نشون بده ،‌سه بار زير هم مياره اطلاعاتش رو.

در ضمن من از adoquery و اس كيو ال سرور 2000 و از دستور LEFT OUTER JOIN براي اتصال جداول استفاده ميكنم.

p_ooya
دوشنبه 06 مهر 1388, 20:23 عصر
در دستور select ای که نوشتید از عبارت distinct استفاده کنید. امیدوارم سوالتون رو درست متوجه شده باشم، چون یه مقدار گنگ بود.

DlphIran
سه شنبه 07 مهر 1388, 13:17 عصر
distinct میاد و براساس فیلد مشخصی ، اطلاعات رو غیر تکراری نشون میده ، اما من به تمام فیلدها برای نمایش اطلاعات نیاز دارم و اگه بیام و جلوی distinct ستاره بزارم یا اسامی همه فیلدها رو بزارم ، نتیجه ای نمی ده .در ضمن فيلد عكس هم دارم

DlphIran
شنبه 11 مهر 1388, 12:26 عصر
اينم كدهايي كه بعد از استفاده ازش در خروجي اطلاعات تكراري مياره يعني بعد از جستجوي روي جدول امانت اگه بخوايم ريز اطلاعات كتابهاي امانت گرفته شده رو ببينيم ،‌اين كدها اجرا ميشن اما حاصلش تكرار كتابهايي است كه بيش از يكبار امانت گرفته شده اند .



with form15.ADOQuery1 do
begin
sql.Clear;
sql.Add('select *');
sql.Add('from ket left outer join sabegh');
sql.add('on ket.sabt=sabegh.sabt');
sql.Add('where sabegh.a>0');
if edit1.Text<>'-' then
begin
sql.Add(' and sabegh.cod=:h');
parameters.ParamByName('h').Value:=edit1.Text;
end;
if edit5.Text<>'-' then
begin
sql.Add(' and sabegh.sabt=:j');
parameters.ParamByName('j').Value:=edit5.Text;
end;
if combobox1.Text='Èáå' then
begin
sql.Add(' and tam=:k');
parameters.ParamByName('k').Value:='Èáå';
end;
if combobox1.Text='뒄' then
begin
sql.Add(' and tam=:k');
parameters.ParamByName('k').Value:='뒄';
end;
if combobox3.Text='Èáå' then
begin
sql.Add(' and dir=:l');
parameters.ParamByName('l').Value:='Èáå';
end;
if combobox3.Text='뒄' then
begin
sql.Add(' and dir=:l');
parameters.ParamByName('l').Value:='뒄';
end;
if combobox2.Text='ÈÑÇÈÑ' then
begin
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and dyb=:a and dmb:b');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
end
else
if (edit26.Text='') and (edit25.Text='') and (edit12.Text<>'') then
begin
sql.Add('and dyb=:a');
parameters.ParamByName('a').Value:=edit12.Text;
end
else
if (edit26.Text<>'') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and dyb=:a and dmb=:b and ddb=:c');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
parameters.ParamByName('c').Value:=edit26.Text;
end
else
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text='') then
begin
sql.Add('and dmb=:b');
parameters.ParamByName('b').Value:=edit25.Text;
end;
end
else
if combobox2.Text='ÈÚÏ ÇÒ' then
begin
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and (dyb=:a and dmb>=:b) or dyb>:c');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
parameters.ParamByName('c').Value:=edit12.Text;
end
else
if (edit26.Text='') and (edit25.Text='') and (edit12.Text<>'') then
begin
sql.Add('and dyb>=:a');
parameters.ParamByName('a').Value:=edit12.Text;
end
else
if (edit26.Text<>'') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and ((dyb=:a and dmb>=:b and ddb=:c) or (dyb=:d and dmb>:e) or dyb>:f)');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
parameters.ParamByName('c').Value:=edit26.Text;
parameters.ParamByName('d').Value:=edit12.Text;
parameters.ParamByName('e').Value:=edit25.Text;
parameters.ParamByName('f').Value:=edit12.Text;
end
else
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text='') then
begin
sql.Add('and dmb>=:b');
parameters.ParamByName('b').Value:=edit25.Text;
end;
end
else
if combobox2.Text='ÞÈá ÇÒ' then
begin
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and (dyb=:a and dmb<=:b) or dyb<:c');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
parameters.ParamByName('c').Value:=edit12.Text;
end
else
if (edit26.Text='') and (edit25.Text='') and (edit12.Text<>'') then
begin
sql.Add('and dyb<=:a');
parameters.ParamByName('a').Value:=edit12.Text;
end
else
if (edit26.Text<>'') and (edit25.Text<>'') and (edit12.Text<>'') then
begin
sql.Add('and ((dyb=:a and dmb<=:b and ddb=:c) or (dyb=:d and dmb<:e) or dyb<:f)');
parameters.ParamByName('a').Value:=edit12.Text;
parameters.ParamByName('b').Value:=edit25.Text;
parameters.ParamByName('c').Value:=edit26.Text;
parameters.ParamByName('d').Value:=edit12.Text;
parameters.ParamByName('e').Value:=edit25.Text;
parameters.ParamByName('f').Value:=edit12.Text;
end
else
if (edit26.Text='') and (edit25.Text<>'') and (edit12.Text='') then
begin
sql.Add('and dmb<=:b');
parameters.ParamByName('b').Value:=edit25.Text;
end;
end;

execsql;
active:=true;


لطفا با توجه به كد بالا راهنماييم كنيد

A.Shafiee
شنبه 11 مهر 1388, 12:40 عصر
به نظرم طراحی database شما مورد داره .
این جستجو داره log امانتی ها رو بر می گردونه
درصورتیکه اگر شما نیاز دارین که وضعیت بودن یا نبودن رو چک کنین ، بهتره از یک فیلد وضعیت کمک بگیرین:لبخندساده:

DlphIran
یک شنبه 12 مهر 1388, 16:23 عصر
منتظر راهنمايي دوستان هستم

DlphIran
چهارشنبه 15 مهر 1388, 15:07 عصر
بيشتر از خيلي منتظرراهنمايي دوستان هستم :قهقهه:

:متفکر::متفکر::متفکر: