| |

VerySource

 Forgot password?
 Register
Search
View: 978|Reply: 8

How to create table names dynamically?

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-21 08:00:02
| Show all posts |Read mode
This is wrong, how can I solve it? Thank you
procedure TForm3.Button2Click (Sender: TObject);
var
  tablename: string;
begin
    tablename: = formatdatetime ('yyyymd', strtodatetime (daystr));
    with ADOquery2 do
    begin
       close;
       sql.Clear;
       sql.Add ('select book number, sales quantity, sales unit price into' + tablename + 'from bookout');
       sql.Add ('where sales date =' + quotedstr (daystr));
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-6 13:45:01
| Show all posts
sql.Add('exec(select book number, sales quantity, sales unit price into'+tablename+' from bookout');
sql.Add('where sales date='''+quotedstr(daystr))+''')';


Your date, I quoted it for you, should be needed.
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-11 16:45:01
| Show all posts
sql.Add('select book number, sales quantity, sales unit price into'+quotedstr(tablename)+' from bookout');
sql.Add('where sale date='+quotedstr(daystr));

That's right
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-11 18:45:01
| Show all posts
What you wrote upstairs is right!
It's tablename. What do you put in quotation marks?


I didn’t see any problem with the sql written by the host, you can try to add a space before where to see, I use adodataset instead of adoquery


sql.Add('select book number, sales quantity, sales unit price into'+tablename+' from bookout');
sql.Add(' where sale date='+quotedstr(daystr));
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Unknown

Post time: 2020-8-11 19:00:01
| Show all posts
It’s not the problem I said, please send your error message to see
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-11 19:15:03
| Show all posts
Where did your daysr come from? Global variables?
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-13 19:00:01
| Show all posts
It is not wrong when using English letters for the table name, but it is wrong when using the date. What is wrong?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-14 11:30:01
| Show all posts
ShowMessage takes a look at the actual statement to see if there are any errors. Such a simple question
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-14 13:00:01
| Show all posts
Try adding a space before where
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