Einzelnen Beitrag anzeigen

Benutzerbild von user0815
user0815

Registriert seit: 5. Okt 2007
331 Beiträge
 
Delphi XE2 Professional
 
#10

AW: SQL Select IN Abfrage mit Parameter ?

  Alt 31. Okt 2012, 10:53
DANKE !
In der Hilfe gefunden, ausprobiert, funktioniert.

Zitat:
Working with Macros
Macros help you to change SQL statements dynamically. They allow partial replacement of the query statement by user-defined text. Macros are identified by their names which are then referred from SQL statement to replace their occurrences for associated values.
First step is to assign macros with their names and values to a dataset object.
Then modify SQL statement to include macro names into desired insertion points. Prefix each name with & ("at") sign to let UniDAC discriminate them at parse time. Resolved SQL statement will hold macro values instead of their names but at the right places of their occurrences. For example, having the following statement with the TableName macro name:

SELECT * FROM &TableName

You may later assign any actual table name to the macro value property leaving your SQL statement intact.

Query1.SQL.Text := 'SELECT * FROM &TableName';
Query1.MacroByName('TableName').Value := 'Dept';
Query1.Open;

UniDAC replaces all macro names with their values and sends SQL statement to the server when SQL execution is requested.
Delphi-Quellcode:
  SQL.Clear;
  SQL.Add('SELECT');
  SQL.Add(' FELD1, FELD2, DATUM');
  SQL.Add('WHERE');
  SQL.Add(' FELD1 IN (&Feldwerte) AND');
  SQL.Add(' DATUM >= :DATE1');
  SQL.Add('ORDER BY');
  SQL.Add(' FELD1 DESC');

  ParamCheck := true;
  ParamByName('DATE1').AsDateTime:= StartOfTheDay(DateTimePicker1.Date);
  MacroByName('Feldwerte').Value := '1,2,3,4,5,6,7,8,9';
  Mit Zitat antworten Zitat