tsql - SQL get single value inside existing query? -


I have a query that returns a bunch of rows but I want to use the same question:

Calculate the total row in the table
Get 2 line numbers where a fixed username is located

just like this I am from:

  BEGIN DECLARE @startRowIndex INT; DECLARE @PageIndex INT; DECLARE @RowsPerPage INT; SET @PageIndex = 0; SET @RowsPerPage = 15; SET @startRowIndex = (@PageIndex * @RowsPerPage) + 1; In the form of the message (select Row_number () as the line (by the order by the DESC score), calculations (different Town. Townned) as the towns, user_details.username, user_score.score, allience.alliencename, allience Include numberofrows interiors from user_details as user.details.username = user_score.username inside user_details.allienceid, allience.alliencetagname, (select count (*) from user_details) city_town.townownname on user_details.username Left External Support Combination allience_roles user_details.useralliencerole = allience_roles.roleid on the left, Select the allience Allience_roles.allienceid = allience.allienceid user_details.username, user_score.score, allience.alliencename, allience.allienceid, allience.alliencetagname) *, (select the line from the messageentries where the user name = 'myUsername') automatically As far as messageentries from @startRowIndex and @StartRowIndex + @RowsPerPage, the row-1 end  

does this work, but to run once for every row in the two nested selection table Do not have the option? : /

  ... (SELECT Count (*) from user_details) as numberofrows ... (SELECT line from messageentries WHERE user name = 'myUsername') itself as  

So my question is how can I achieve those values ​​that I would probably like as "low-cost", and the same question in priority?

Thank you in advance :)

try it ...

  select DECLARE @NumberOfRows INT @NumberOfRows = count (*) with user_details (select ROW_NUMBER (more than selected ROW_NUMBER), as the command line (calculated by DISTINCT town.townid) In the form of cities, users_details.username, user_score.score, allience.alliencename, allience.allienceid, allience.alliencetagname, @NumberOfRows as number number user_score INNER user_score ON user_details.use Rname = user_score.username INNER in the city Join user_details.username = town.townownername LEFT over user_details.useralliencerole at al Insert lience_roles.Allius_roles.Rolide left OUTER allience_roles.allienceid = user name, user_score.score, MyRowNumber.no, * MyRowNumber.row * by allience.allienceid group, through my message as MyRowNumber.row (Save Content Message name where user name = 'myUsername') is between @startRowIndex and @StartRowIndex + @RowsPerPage - 1  
between the MyRowNumber WHERE line

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -