Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server, insert value to variable and sort
    primarykey
    data
    text
    <p>I need to sort the results of a query after insert a value to a variable. I am trying to sort according to 'RowId' but its not valid in my case.<br> Below is my query, how can I make it work? Thanks.</p> <pre><code>SELECT TOP 1 @NumOfProducts = ROW_NUMBER() OVER(ORDER BY Products.Id) AS RowId FROM Cities INNER JOIN CitiesInLanguages ON Cities.Id = CitiesInLanguages.CityId INNER JOIN ShopsInCities ON Cities.Id = ShopsInCities.CityId INNER JOIN Categories INNER JOIN ProductstInCategories ON Categories.Id = ProductstInCategories.CategoryId INNER JOIN Products ON ProductstInCategories.ProductId = Products.Id INNER JOIN ProductsInProdutGroup ON Products.Id = ProductsInProdutGroup.ProductId INNER JOIN ProductsGroups ON ProductsInProdutGroup.ProductGroupId = ProductsGroups.Id INNER JOIN ShopsInProductsGroup ON ProductsGroups.Id = ShopsInProductsGroup.ProductGroupId INNER JOIN aspnet_Users ON ShopsInProductsGroup.ShopId = aspnet_Users.UserId ON ShopsInCities.ShopId = aspnet_Users.UserId INNER JOIN ProductsNamesInLanguages ON Products.Id = ProductsNamesInLanguages.ProductId INNER JOIN UsersInfo ON aspnet_Users.UserId = UsersInfo.UserId INNER JOIN ProductOptions ON Products.Id = ProductOptions.ProductId INNER JOIN ProductOptionsInLanguages ON ProductOptions.Id = ProductOptionsInLanguages.ProductOptionId INNER JOIN ProductFiles ON Products.Id = ProductFiles.ProductId INNER JOIN ProductsInOccasions ON Products.Id = ProductsInOccasions.ProductId INNER JOIN Occasions ON ProductsInOccasions.OccasionId = Occasions.Id INNER JOIN OccasionsInLanguages ON Occasions.Id = OccasionsInLanguages.OccasionId WHERE (Products.IsAddition = 0) AND (Categories.IsEnable = 1) AND (Products.IsEnable = 1) AND (ProductsGroups.IsEnable = 1) AND (Cities.IsEnable = 1) AND (ShopsInProductsGroup.IsEnable = 1) AND (CitiesInLanguages.CityName = @CityName) AND (ProductsNamesInLanguages.LanguageId = @languageId) AND (Categories.Id = @CategoryId) AND (ProductOptions.IsEnable = 1) AND (ProductFiles.IsEnable = 1) group by Products.Id, ProductsNamesInLanguages.ProductName, UsersInfo.Name Order By RowId </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload