0

I have the following SQL and trying to generate a number next to each condition it meets for each record it produces.

SELECT TOP 10 
    [Account],
    [Account Name],
    generate #
FROM
    Supplier
WHERE
    Account Name IN ('JP', 'TC', 'KA')

So it would be something like this,

Account    Account Name      Generate #
---------------------------------------
T1000          JP                 1
T1001          TC                 2
T1033          KA                 3
T1039          KA                 4

So Generate # is what I'm trying to do in SQL Server.

Thanks for your time.

2
  • What do you mean by "condition"? Commented Feb 20, 2019 at 17:09
  • you've got a top 10 without an order by. This will result in a random top 10 Commented Feb 20, 2019 at 17:22

1 Answer 1

2

Use ROW_NUMBER():

select top 10 [Account], [Account Name],
       row_number() over (order by Account) as seqnum
from Supplier
where [Account Name] in ('JP','TC','KA')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.