Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM SQL » View Thread |
Messages 1 to 3 of 3 total |
increment a field |
Mon, Apr 14 2008 12:41 PM | Permanent Link |
Khaled Homouda | Hello all
I have a table which is already a child table with a field called category where I need to enter either 'Right' or 'left' in it and another field called number where I need to autincrement numbers in it, in code, accordeing to either 'left' or 'right'. I don't know how to implement it, code or SQL thanks Khaled |
Mon, Apr 14 2008 1:53 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Khaled
I'm not sure just what you're asking for but if my interpretation is right it should be simple enough. You need another small table (AUTOLR) to hold the last number used. I'd have two fields LeftRight (string 1 - primary ID) and LastNumber (integer). There would be two records L and R. LastNumber would hold the last number used in the fields you need to autoinc. Create a BeforePost event for the table you're editing and in it check the value of the field you edit and enter either left or right. Use that to do a AUTOLR.FindKey get the LastNumber, increment it, set the value in your table to that AND set LastNumber in AUTOLR Job done. Roy Lambert [Team Elevate] |
Mon, Apr 14 2008 2:21 PM | Permanent Link |
Khaled Homouda | Thanks Roy, very nice and simple solution, I was thinking of doing it by this function just thought of
Function DBNextIntegerIn(SessionName, DatabaseName, TableName, FieldName, Olaterality: String; CycNo : Integer):LongInt; Var Query : TDBISAMQuery; CurrentMax : LongInt; NewMax : LongInt; Begin CurrentMax := 0; Query := TDBISAMQuery.Create(nil); Try Query.SessionName := SessionName ; Query.DatabaseName := DatabaseName; Query.SQL.Clear; Query.SQL.Add('Select '); Query.SQL.Add('Max('+FieldName+')'); Query.SQL.Add('From '); Query.Sql.Add('"'+TableName+'"'); Query.Sql.Add('WHERE CycleNo = '+ IntToStr(CycNo) ) ; Query.Sql.Add('AND ovary = '+ Olaterality) ; Query.Open; Try CurrentMax := Query.Fields[0].AsInteger; Except End; NewMax := CurrentMax + 1; Result := NewMax; Finally Query.Free; End; End; of course yours is simpler thanks Khaled |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |