locked
how to convert from query to SQL RRS feed

  • Question

  • I'm using visual studio database. I'm using the query in the visual studio database and I got this code:
    SELECT TOP (1) LogId FROM Users ORDER BY Id DESC
    I now need to use the above statement and change it to something like that:
    string sql = "UPDATE Users set Logout=@Logout where name=@Name";
    Can someone tell me how should I do so that I can select the top entry?
    Friday, November 4, 2011 1:33 AM

Answers

  •  

    ;with cte as (select LogID, Logout, Name, row_number() over (partition by LogID order by ID DESC) as Rn from Users where Name = @Name)
    
    update cte set Logout = @Logout where Rn = 1
    

     


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Friday, November 4, 2011 3:37 AM
    Answerer