0

I have a table that has 200 records. The columns in the table are

Client_id, Name, age, dob

sample data:

enter image description here

Now I have a select statement that needs to generate sequential number but not from the table.

So my select statement is:

select row_number, client_id, name from #temp1....

I don't want to get the number from the #temp1 table rather I want to generate dynamically on the fly.

any help?!

2
  • Are you using MySQL or SQL Server? (Or something completely different?) You tagged both, maybe by accident? Commented Oct 8, 2018 at 22:07
  • I am using SQL server. Tagged my mistake Commented Oct 8, 2018 at 22:08

1 Answer 1

2

Try using row_number(). For example:

SELECT row_number() OVER (ORDER BY client_id) row_number,
       client_id,
       name
       FROM #temp1;

Possibly change the ORDER BY clause, if you don't want the numbers to be ordered by the client ID.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This is what I needed.

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.