Home > Software engineering >  Sequence row in SELECT Query
Sequence row in SELECT Query

Time:01-12

I have a simple SELECT statement in need sequence number according to result (no need to group or order by)I Used Row_Number but it need Over. any other way to do it? Please help

SELECT 
    ROW_NUMBER() OVER () AS ArrayId (:here i need sequence number)
    , TRIM(CM.Category) as Category
    , TRIM(CM.SubCategory) as SubCategory
    , CM.PlantCode
    , ISNULL(PM.PlantName,'') as PlantName
    , CM.Capacity AS Capacity_
    , CM.SizeRange
    , CM.CapacityId 
FROM capacitymaster2 CM
LEFT JOIN PlantMaster2 PM ON CM.PlantCode = PM.PlantCode
WHERE CM.SubCategory IS NOT NULL AND CM.SubCategory != ''

CodePudding user response:

Try: ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) if you need a unique sequence number, but don't care about the actual order.

  • Related