-
Jan 23rd, 2007, 10:19 PM
#1
Thread Starter
Addicted Member
[RESOLVED] serial number in recordset when such field not available
Hi all
I have a table customers with fields
custcode
custname
city
SELECT srno, custname FROM customers ORDER BY custname
In this query, srno should increament automatically.
Is it possible?
I want to fire a query which will give me following result.
1 customer1
2 customer2
etc
Thanks
-
Jan 24th, 2007, 12:26 AM
#2
Hyperactive Member
Re: serial number in recordset when such field not available
In this query, srno should increament automatically. Is it possible?
No! srno is not a field in your table so it cannot be selected by your query.
Add a new field to your table called srno and set it to auto increment, then your query will work.
-
Jan 24th, 2007, 12:40 AM
#3
Re: serial number in recordset when such field not available
what is the database that you are using...try ROW_NUMBER()
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jan 24th, 2007, 12:48 AM
#4
Thread Starter
Addicted Member
Re: serial number in recordset when such field not available
Thanks for reply.
GaneshMoorthy:
Data base is MS SQL Server.
How to use row_number is select query. will you pls give an example.
Will row_number work properly with ms sql server database table?
LinXg:
Autoincreament field may not be possible in this case as query is intended for data ordered by custname field and where data insert might have happened in any order and so autoincreament field may not have serial values.
-
Jan 24th, 2007, 12:58 AM
#5
Re: serial number in recordset when such field not available
Radhesham, I found this example to get a rownumber in your query...
VB Code:
SELECT CustCode, CustName,
(SELECT COUNT(*) FROM Customers C2 WHERE C2.CustCode >= C.CustCode) AS SrNo
FROM Customers C
ORDER BY CustCode
hope this works for you...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jan 24th, 2007, 01:03 AM
#6
Thread Starter
Addicted Member
Re: serial number in recordset when such field not available
Thanks.
Thank you for providing exact solution.
Radhesham
-
Jan 24th, 2007, 01:07 AM
#7
Re: [RESOLVED] serial number in recordset when such field not available
Radhesham: You are most welcome !
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|