Delphi7 TADOQuery filter not accurate at quick report - sql

i want to show report with date range
i have code
procedure TForm1.ButtonPreviewClick(Sender: TObject);
begin
...
ADOQuery1.Active := False;
ADOQuery1.SQL.Text:='';
ADOQuery1.SQL.Text :='SELECT * FROM tablename WHERE datefield BETWEEN :startdate and :enddate';
ADOQuery1.Parameters.ParamByName('startdate').DataType:= ftdate;
ADOQuery1.Parameters.ParamByName('endate').DataType:= ftdate;
ADOQuery1.Parameters.ParamByName('startdate').value:= datetostr(DateTimePicker1.Date);
ADOQuery1.Parameters.ParamByName('enddate').value:= datetostr(DateTimePicker2.Date) ;
ADOQuery1.Active := True;
QuickRep1.Preview;
...
end;
and i put 4 test records to tablename
number|date
1 |14/8/2015
2 |1/8/2015
3 |31/8/2015
4 |9/8/2015
if i click the button, quick report only showing first record, no matter what date i choose, like this
quickreport
number|date
1 |14/8/2015
with quick report properties
qrband title = qrlabel1 with caption 'quickreport'
qrband column header = qrlabel2 with caption 'number', qrlabel3 with caption'date'
qrband detail = qrdbtext1 & qrdbtext2 with dataset 'adoquery1', datafield 'numberfield' on qrdbtext1 and 'datefield' on qrdbtext2
how to show all data with date range filter?
thanks for your attention

Related

How to display records with certain date from an editbox using ms access and delphi 7

I have a table in MS Access with a name MembersAccount and one of the field name as DatePaid. I am trying to display records from a date entered in an editbox but the output is not displaying any records at all. This is the code I am using.
if ADOQuery1.Locate('datepaid',edit1.Text,[]) THEN
begin
open;
SQL.Clear;
qry:= 'Select * from MembersAccount WHERE((MembersAccount.[DatePaid])='+edit1.Text+')';
SQL.Add(qry);
Active:= True;
Where am I getting the code wrong? Date entered in the editbox is in dd/mm/yyyy format
Use parts like these (not full code):
editStr := edit.Text;
myDate := StrToDate(editStr);
sqlDate := FormatDateTime('yyyy/mm/dd', myDate);
qry:= 'Select * from MembersAccount WHERE((MembersAccount.[DatePaid]) = #' + sqlDate + '#)';

Using ACCEPT, CASE to create CURSOR in pl/sql

I am trying to create a script that will allow the user to select which CASE population to use from an ACCEPT when gathering student contact info.
PROMPT 'Select a popluation for emails'
PROMPT '1. Currently registered'
PROMPT '2. New Applicants'
PROMPT
ACCEPT cnt number PROMPT 'Selection: ';
...
CURSOR stu_lst IS
CASE &cnt
WHEN 1 THEN -- Current registered students.
select distinct SFRSTCA_PIDM pidm
from SFRSTCA
where SFRSTCA_TERM_CODE = '201403' and
SFRSTCA_LEVL_CODE = '01' and
SFRSTCA_RSTS_CODE = 'RE';
WHEN 2 THEN -- New applicants
select app_pidm pidm
from app
where app_term = 'Fall 2014';
ELSE
-- Incorrect selection.
DBMS_OUTPUT.PUT_LINE('Incorrect selection made.');
exit;
END;
END;
Assuming the two queries return the same data type, you could use a union with a filter that checks the variable in each part; something like:
DECLARE
CURSOR stu_lst IS
-- Current registered students.
select distinct SFRSTCA_PIDM pidm
from SFRSTCA
where &cnt = 1 and
SFRSTCA_TERM_CODE = '201403' and
SFRSTCA_LEVL_CODE = '01' and
SFRSTCA_RSTS_CODE = 'RE';
UNION ALL
-- New applicants
select app_pidm
from app
where &cnt = 2 and
app_term = 'Fall 2014';
invalid_argument EXCEPTION;
...
BEGIN
IF &cnt NOT IN (1, 2) THEN
RAISE invalid_argument;
END IF
FOR rec IN stu_lst LOOP
h_pidm := rec.pidm;
...
END LOOP;
EXCEPTION
WHEN invalid_argument THEN
dbms_output.put_line('Incorrect selection made.');
END;
/
You could also declare a cursor variable and open that with the appropriate query, inside a case statement within the main body of the block. This sticks with your explicit cursor syntax though.

delphi - Save multiple records at once

Dont know how to formulate this exactly so bear with me please... I am saving text from a memo to a database with date selected in the PlannerCalendar1. Since I can select multiple dates in the PlannerCalendar1, how can I post the value of the memo to all dates selected in the PlannerCalendar1?So when I click 'save' the contents of the memo gets saved to all selected dates.Database is SQLite. The table also has an ID field which is autoinc (primary).PlannerCalendar is from the set of TMS components.
procedure TForm1.cxButton1Click(Sender: TObject);
var i:integer;
begin
with UniQuery1 do
begin
UniQuery1.SQL.Text:='INSERT INTO LOG (DATE,PERSON,DONE,TIME) VALUES (:a1,:a2,:a3,:a4)';
UniQuery1.PARAMS.ParamByName('A1').VALUE := PlannerCalendar1.Date;
UniQuery1.PARAMS.ParamByName('A2').VALUE := cxmemo1.Lines.text ;
UniQuery1.PARAMS.ParamByName('A3').VALUE := (0);
UniQuery1.PARAMS.ParamByName('A4').Value := AdvOfficeStatusBar1.Panels[0].Text;
UniQuery1.ExecSQL;
cxmemo1.Clear;
UniTable1.Refresh;
Tried this at the end but it wont work :
with plannercalendar1.Dates do
begin
for i := 0 to -1 do
begin
UniQuery1.PARAMS.ParamByName('A1').VALUE :=plannercalendar1.dates.Add + i ;
UniQuery1.ExecSQL;
end;
I have no idea what a PlannerCalendar is, but presumably there's some way to get at the list of dates that are selected. You want to do something like this:
UniQuery1.SQL.Text:='INSERT INTO LOG (DATE,PERSON,DONE,TIME) VALUES (:a1,:a2,:a3,:a4)';
UniQuery1.PARAMS.ParamByName('A2').VALUE := cxmemo1.Lines.text ;
UniQuery1.PARAMS.ParamByName('A3').VALUE := (0);
UniQuery1.PARAMS.ParamByName('A4').Value := AdvOfficeStatusBar1.Panels[0].Text;
for i := 0 to PlannerCalendar1.NumberOfDatesSelected-1 do begin
UniQuery1.PARAMS.ParamByName('A1').VALUE := PlannerCalendar1.SelectedDate[i];
UniQuery1.ExecSQL;
end;
Of course, NumberOfDatesSelected and SelectedDate are wild guesses. You'll need to find out what they're really called.
You need to use the Planner's SelectionToAbsTime method :-
Var
lStart, lEnd : TDateTime;
Begin
Planner1.SelectionToAbsTime(lStart, lEnd);
For I := Trunc(lStart) To Trunc(lEnd) Do
SaveMemosForDate(I);
End;

How to extract data from a databse and into E.g a Label editbox?

I got a Label3 and a richedit where I want to show information on. I want the information from a database (Specificly from the table - Candidate_table). Candidate table has these Columns :
Name * Surname * Grade * Service_Points * Slogan * Description
There will be exactly 5 candidates , so each column will be filled out 5 times.
So here is what I want to do:
Whenever I click on the combobox the 5 candidate's names will display. When I cick on a Specific name E.g John I want his slogan to display on the Label3 and his Description in the Richedit1.
So I am trying this (onchange) :
case DBCombox1.Itemindex of 0 : begin
Candidate_table.Fieldbyname('Name').asString := DBCombobox1.text[0];
Adoquery1.active := false;
Adoquery.sql.text := 'Select Slogan, Description from candidate table where name = Candidate_table.Fieldbyname('Slogan').asString;
adoquery1.active := true;
label3.caption := Candidate_table.Fieldbyname('Slogan').asString ;
Richedit1.lines.add(Candidate_table.Fieldbyname('Description').asString) ;
end;
So this is'nt working...
Can i do this what I want or should I change my form >?

SQL table change sequence

I have a table displayed in DBGrid the sort order is based on a Sequence field and I want to be able to move an item up or down one place at a time. I have researched here and cannot find anything exactly like I need.
The problem comes when I disable the Sort order to make a change, the list reverts to the order in which the data was originally entered, so I have lost the item next in line.
This is what I have...
Folder Sequence
----------------
Buttons 1
Thread 2 << Current Row
Cotton 3
Rags 4
On clicking the "MoveDown" button I want...
Folder Sequence
----------------
Buttons 1
Cotton 2
Thread 3 << Current Row
Rags 4
But - when I remove the Sort order on Sequence I get the order I entered the items...
Folder Sequence
----------------
Buttons 1
Cotton 2
Rags 4
Thread 3 << Current Row
So far my attempts are proving pretty cumbersome and involve loading the Rows into a listbox, shuffling them and then writing them back to the Table. Gotta be a better way, but it is beyond my current grasp of SQL.
Can someone please point me in the direction to go.
I don't want to trouble anyone too much if it is a difficult thing to do in SQL, as I can always stay with the listbox approach. If it is relatively simple to an SQL-expert, then I would love to see the SQL text.
Thanks
My solution is based on the TDataSet being sorted by the Sequence field:
MyDataSet.Sort := 'Sequence';
And then swapping the Sequence field between the current row and the Next (down) / Prior (up) records e.g.:
type
TDBMoveRecord = (dbMoveUp, dbMoveDown);
function MoveRecordUpDown(DataSet: TDataSet; const OrderField: string;
const MoveKind: TDBMoveRecord): Boolean;
var
I, J: Integer;
BmStr: TBookmarkStr;
begin
Result := False;
with DataSet do
try
DisableControls;
J := -1;
I := FieldByName(OrderField).AsInteger;
BmStr := DataSet.Bookmark;
try
case MoveKind of
dbMoveUp: Prior;
dbMoveDown: Next;
end;
if ((MoveKind = dbMoveUp) and BOF) or ((MoveKind = dbMoveDown) and EOF) then
begin
Beep;
SysUtils.Abort;
end
else
begin
J := DataSet.FieldByName(OrderField).AsInteger;
Edit;
FieldByName(OrderField).AsInteger := I;
Post;
end;
finally
Bookmark := BmStr;
if (J <> -1) then
begin
Edit;
FieldByName(OrderField).AsInteger := J;
Post;
Result := True;
end;
end;
finally
EnableControls;
end;
end;
Usage:
MoveRecordUpDown(MyDataSet, 'Sequence', dbMoveDown);
// or
MoveRecordUpDown(MyDataSet, 'Sequence', dbMoveUp);
If i understand right, you want to find "next sequence item"?
May be you may do something like "get first min value, grater then X"?
In this way, you can pass prev. Row sequence value.