Q&A

  • combobox와 sql문에 대한 질문
Query2.SQL.Add('select a.party, count(*) GetSeat from (select distinct party, small_district, gain from election where big_district = :BDistrict) a, ');

Query2.SQL.Add('(select small_district, max(gain) max_gain from election group by small_district) b ');

Query2.SQL.Add('where a.small_district = b.small_district and a.gain = b.max_gain ');

Query2.SQL.Add('group by party');

BDistrict := CbDistrict.ItemIndex;



위의 sql에서처럼 BDistrict란 combobox의 item번호를 직접 sql문안에 넣을 수는 없는건가요?

자꾸 에러가 나네요..^^

1  COMMENTS
  • Profile
    이성찬 2001.11.01 01:25
    'BDistrict' 가 TComboBox 의 Name 속성인가요?

    만일 그렇다면 SQL문이 string 이므로 다음과 같이 하셔야 하지 않을까요?



    Query2.SQL.Add('select a.party, count(*) GetSeat from (select distinct party, small_district, gain from election where big_district = ' + Trim(IntToStr(BDistrict.ItemIndex)) + ') a, ');



    그렇지 않고 'BDistrict' 가 Query2 의 Parameter 라면 다음과 같이 해야죠.



    with Query2 do

    begin

    ParamByName('BDistrict').Value := BDistrict.ItemIndex;

    end;



    물론 두번째의 경우라면 'BDistrict' 라는 파라미터의 타입은 당근 integer야 겠죠.