| |

VerySource

 Forgot password?
 Register
Search
View: 890|Reply: 3

delphi + sql prevent the problem of duplicate temporary tables

[Copy link]

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-11 01:30:01
| Show all posts |Read mode
I have encountered the following problems for beginners, please help me master! Thank you! delphi + sql

      I make a purchase order for invoicing. The purchase order is divided into main form and detailed form. Now when adding the details, we need to build a temporary table to ensure that there are no duplicates in the temporary table. However, no temporary table will be built, and I don't know how to deal with it. Are there any better solutions for you?

      Master table (jh_master (dh single number (primary key), ghs supplier, jhdate purchase date))
     List (jh_detail (dh single number (primary key), spno product number (primary key), qty quantity))

Now enter the page first to add the main table information, add multiple details, use adoquery.append to add. But because my dbgrid settings are not automatically saved in the database, I have to wait until saving before adoquery.updatebatch saves. To prevent product numbers from being duplicated in the same document. What should i do note. At adoquery.append, the data is not stored in the database, so you cannot check for duplicates. Every time I think about building a temporary table, I won't. What to do!
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-17 15:30:01
| Show all posts
Think of ways to generate numbers;
Not to judge in the fact table, but to judge in the special storage current number;
For example: you can store the current maximum number of the table in a table t1 alone; then trigger a stored procedure to generate a new product number for an event;
fx:
Table t1;
f1 f2
Article id sp000001
Customer number kh000001


create procedure createNewID
@ f1 varchar (20),
@ReturnID varchar (20)
as

declare
  @NewID varchar (20),
  @CurrID varchar (20)
--Get the current number
  select @CurrID = f2 from t1 where f1 = @ f1
--Get the current number
  set @newID = convert (varchar (20), convert (int, right (@ currid, 6)))
  set @ReturnID = left (@ Currid, 8-len (@Newid)) + @ Newid
go


--Test Results
declare
  @Newid varchar (20)
exec createNewID 'Product ID', @NewID output
print @Newid
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-17 16:45:01
| Show all posts
Sorry; I forgot a sentence above to update the current id back to the number storage table;
The complete code should be:
create procedure createNewID
@ f1 varchar (20),
@ReturnID varchar (20)
as

declare
@NewID varchar (20),
@CurrID varchar (20)
--Get the current number
select @CurrID = f2 from t1 where f1 = @ f1
--Get the current number
set @newID = convert (varchar (20), convert (int, right (@ currid, 6)))
set @ReturnID = left (@ Currid, 8-len (@Newid)) + @ Newid
--Update the current latest number
update t1 set f2 = @ReturnID where f1 = @ f1
go
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-6 12:45:01
| Show all posts
create table #T(id int,...)
With a "#", it is a temporary table.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list