Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to generate a auto no in a col.

Author  Topic 

RoniDxb
Starting Member

28 Posts

Posted - 2008-08-05 : 10:10:29
myTable

Items...................................

Mouse................................
Keyboard.............................
Printer..............................
Keyboard.............................
Mouse....


myTable has only one col name Items, can we generate auto serial no while selecting items column from myTable like below.

Sr......Items...................................

1......Mouse................................
2......Keyboard.............................
3......Printer..............................
4......Keyboard.............................
5......Mouse....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-05 : 13:41:10
is there any other columns in your table?
Go to Top of Page

RoniDxb
Starting Member

28 Posts

Posted - 2008-08-05 : 14:06:33
No
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-05 : 14:12:37
then what decides your order of serialising?
Go to Top of Page

RoniDxb
Starting Member

28 Posts

Posted - 2008-08-05 : 14:50:59
quote:
Originally posted by visakh16

then what decides your order of serialising?



ok, Visakh bofore two or three days ago i have put a Topic name " How to find sum of previous rows in every new row "
and visakh you have given me the solution and it also works successfully.
before i describe my problem i would like to review that problem for your convience

problem was following.

View Ledger
Sr.....Debit.......Credit.....Balance.

1......100.........0..........100.....
2......100.........0..........200.....
3......0...........50.........150.....
4......100.........0..........250.....

We can only enter Sr, Debit and Credit where Balance Column should be automatically calculate in the View.
Note Balance = Debit - Credit + Balance(of last row)
plz help me
Plz note Table Ledger only have Cols ( Sr, Debit and Credit)

and ur answer was following

CREATE VIEW YourView
AS
SELECT Sr,
Debit,
Credit,
(SELECT SUM(Debit)-SUM(Credit) FROM YourTable WHERE Sr<=t.Sr) AS Balance
FROM YourTable t
GO

this solution works successfully.
but now the problem is I have no "Sr" column in my View becoz of this i want to generate auto Serial No sothat i could be able to produce Balance.
Actually My main problem is to find the balance.
If balance is calculaed without any SerialNo then it is good.

can u plz help me how to solve this problem.




Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-05 : 16:45:02
Now that we've reviewed the problem that you have already solved, what is the answer to Visakh's question regarding your current problem:
>>then what decides your order of serialising?

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -