I have a problem with a long sql query that don't work.
It say "Cannot open a non-selected statement. But i have a output in the last .Add.
DATA.QueryIL2.Close;
DATA.QueryIL2.SQL.Text := 'DECLARE @t TABLE (Myint1 int, Myint2 int)';
DATA.QueryIL2.SQL.Add( 'INSERT INTO @t Select distinct Myint1 , Myint2 from myTable');
DATA.QueryIL2.SQL.Add( 'Where Myint3 =''' + Myint3 + '''');
DATA.QueryIL2.SQL.Add( 'Select sum(CAST(Myint2 as int)) as MyOut from @t ');
DATA.QueryIL2.SQL.SaveToFile('700.sql');
DATA.QueryIL2.Open;
The Query works fine when i execute in the sql manager tool.