Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TableName as parameter in query MSSQL

Status
Not open for further replies.

castore

Programmer
Apr 1, 2005
18
IT
How can i write in right manner this ?:

select * from :table
in D7 + MsSQL

I need to set tablename at runtime

thanks to all
 
You cannot set the table name using the : technique because this is for accessing fields only.

You need to change the table name in the SQL statement. For example, if you wished to change the table name in a TQuery:
Code:
var
  tablename: string;
...
  tablename := 'MENSA';
...
  Query.Close;
  Query.SQL.Text := Format( 'SELECT * FROM %s', [tablename] );
  Query.Open;
Sometimes the requirement to change the table name at runtime indicates that the database design requires normalisation.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top