Migration From SQL Server to UniSQL: Select top (n) clause
Migration From SQL Server to UniSQL: Select top (n) clause
Hi all,
how could I translate a SQLServer Statement such as
select top 1 from mytable
into UniSQL statement ?
Many thanks in advance
Marco
how could I translate a SQLServer Statement such as
select top 1 from mytable
into UniSQL statement ?
Many thanks in advance
Marco
-
AndreyZ
Hello,
You should not use the TUniSQL component for executing SQL statements that return rows from the database. You should execute this SQL statement in the TUniQuery component. Here is a code example:
You should not use the TUniSQL component for executing SQL statements that return rows from the database. You should execute this SQL statement in the TUniQuery component. Here is a code example:
Code: Select all
UniQuery.SQL.Text := 'select top 1 * from mytable';
UniQuery.Open;-
AndreyZ
-
AndreyZ
Thank you for your answer.
Ok. I'm referring exclusively to migration wizard of visual studio and to UniSql language (not a component) used with UniCommand.
My questions (relate only to this context) are
1) how could I write in unified manner "select top 1 ....". Is it possible (I use only SQLServer and Oracle)
2) the migration wizard of vs doesn't work with AppCode of web service
For question 2 I've found a radical work-around: transfer all AppCode in a normal c# project and call it from ws
For question 1 I've not answer
Best Regard
Marco
Ok. I'm referring exclusively to migration wizard of visual studio and to UniSql language (not a component) used with UniCommand.
My questions (relate only to this context) are
1) how could I write in unified manner "select top 1 ....". Is it possible (I use only SQLServer and Oracle)
2) the migration wizard of vs doesn't work with AppCode of web service
For question 2 I've found a radical work-around: transfer all AppCode in a normal c# project and call it from ws
For question 1 I've not answer
Best Regard
Marco
-
AndreyZ
You can use macros to implement such functionality. For example, you can write the following code:, and for SQL Server use this code:, and for Oracle use this code:For more information about macros, please read the "Working with macros" topic of the UniDAC documentation.
Code: Select all
UniQuery.SQL.Text := 'select &mssql from test_table &ora';Code: Select all
UniQuery.MacroByName('ora').Active := false;
UniQuery.MacroByName('mssql').Active := true;
UniQuery.MacroByName('mssql').AsString := 'TOP 1';Code: Select all
UniQuery.MacroByName('mssql').Active := false;
UniQuery.MacroByName('ora').Active := true;
UniQuery.MacroByName('ora').AsString := 'WHERE ROWNUM < 2';