Search code examples
sql-serveroraclemigrationrownum

Need to convert Oracle to Mssql


SELECT COLUMN FROM TABLE WHERE ACTION='ABC' AND ROWNUM<=1;

I have a doubt in mssql. I need to migrate the above oracle query into mssql. I'm struggling with ROWNUM.


Solution

  • SELECT TOP 1 COLUMN 
    FROM TABLE 
    WHERE ACTION='ABC'
    

    You may need to use Order By too, which is...

    SELECT TOP 1 COLUMN 
    FROM TABLE 
    WHERE ACTION='ABC' 
    Order by columnnane asc/desc 
    

    note: if you don't specify the direction (ASC / DESC) after the Order By, the default is ASC.