全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1138
推到 Plurk!
推到 Facebook!

Insert Autonumber in table with constrain?

答題得分者是:Justmade
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-08 22:32:11 IP:217.34.xxx.xxx 未訂閱
In a table, I configed a field as 'Autonumber', but I do not want it to be 1,2,3,4,5. but I want it to look like this '0001', '0002'. How can I achieve this? thanx
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-08 23:31:21 IP:61.221.xxx.xxx 未訂閱
There is no way to set an identity column to store this value. I suggest you other approach to reach this.    Create another table no_gen with column PNO (INT), CREATETIME (DATETIME). Set the column PNO as an identity column.    If your original table is ORDERS with column PNO (INT), xxxx (datatype), ....., Set the column PNO as datatype of char(4)    Before you insert a new ORDERS record, insert a new record into table no_gen with:    SET NOCOUNT ON;INSERT INTO no_gen (CREATETIME) VALUES (getdate());SELECT @@IDENTITY to get the new PNO value, and then use dephi procedure (sPNO := RightStr('0000' INTTOSTR(iPNO),4)) to fulfill the value with '0' like '0001', '0002' and then insert the ORDERS table with: 'INSERT INTO ORDERS (PNO, XXX1, ...) VALUES ( ' sPNO ', ....... ) This method may not be best, but it works!!
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-09 00:01:00 IP:218.16.xxx.xxx 未訂閱
In the table / query linking to that autonumber table : 1. double click that table/query 2. in the field editor, right click and select add all fields 3. Click the autonumber field 4. In the property edit, change to event page 5. setup the onGetText Event : Text := Format('%4.4d',[Sender.AsInteger]); 6. setup the onSetText Event : Sender.AsInteger := StrToInt(Text); That's it.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-09 00:24:46 IP:217.34.xxx.xxx 未訂閱
THanks Justmade u are always my lifesaver
系統時間:2024-07-01 18:58:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!