Can I create table in sql using delphi edit as a name

Viewed 155

In my program I would like to create a new table whenever I click a button. Table name is supposed to be in the Edit.Text. I made it this way:

procedure TRyby_Form01.WyjazdyBTNClick(Sender: TObject);
var Wyjazd  : string; 
begin
  Wyjazd := WyjazdEDT.text;      // edit wchich is supposed to be table name
  with wyjazdquery3 do

    begin
      parameters.ParamByName('wyjazd').value := wyjazd;
    end;

    wyjazdquery3.ExecSQL;

    with wyjazdquery4 do
    begin
      parameters.ParamByName(':wyjazd').value := wyjazd;
    end;

    wyjazdquery4.ExecSQL;
    wyjazdquery5.ExecSQL;
  end;

end.

I have created parameter as a string in a query and made this syntax

Create Table :wyjazd (
Ryba char(20),
Miara int,
Waga decimal(6,3),
Data date,
przyneta char(60),
metoda char (20) );

Unfortunately when I click the button, all I receive is "incorrect syntax near @P1". Is it possible to make it the way I tried or SQL doesn't allow it?

1 Answers

Easiest way is to use Format with %s for Table name. Simply said - you cant change structure of SQL with parameters. Use this string as template for Query.SQL:

Create Table %s (
Ryba char(20),
Miara int,
Waga decimal(6,3),
Data date,
przyneta char(60),
metoda char (20) );
Related