473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is it posible in sqlserver 2000

284 100+
is it possible to make a running field total in sqlserver 2000 views
and if so how?
can any body answer me
thanks
Nov 8 '07 #1
6 1092
jamesd0142
469 256MB
I don't understand what your asking.
Could you explain in more detail what you require?
Nov 8 '07 #2
muddasirmunir
284 100+
i mean that i want a ruuning total field in sql server 2000 just as we can make a runnig total field in crytal report . for e-g

Sale----------------Balance

100-----------------100

50-------------------150

100------------------250

25-------------------275

here sale colums is the database field which actually stored data and i want to add a balance field which add current record data plus the previous balance

how can i do this in views







I don't understand what your asking.
Could you explain in more detail what you require?
Nov 9 '07 #3
Jim Doherty
897 Expert 512MB
i mean that i want a ruuning total field in sql server 2000 just as we can make a runnig total field in crytal report . for e-g

Sale----------------Balance

100-----------------100

50-------------------150

100------------------250

25-------------------275

here sale colums is the database field which actually stored data and i want to add a balance field which add current record data plus the previous balance

how can i do this in views

Provided you have a field in the resultset to determine hierarchy ie something other than just the sale amount lets say an unique numeric ID field in a table called tblSale (needed to determine the row) then the following SQL will return your requirement

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Sale,
  3.              (SELECT     SUM(Sale)
  4.              FROM         tblSale a
  5.              WHERE     id <= tblSale.id) AS Balance
  6. FROM    tblSale
  7.  
Regards

Jim :)
Nov 9 '07 #4
jamesd0142
469 256MB
Expand|Select|Wrap|Line Numbers
  1. declare @a int
  2. declare @b int
  3. declare @counter int
  4. declare @counter2 int
  5. declare @count int
  6.     set @count = (select Count(*) from james)
  7.     set @counter = 0
  8.     set @a = (select top 1 (col) from james)
  9.     set @b = (select col01 from james where col = @a) 
  10. if @a = 1
  11.     begin
  12.         set @counter = (@counter + @b)
  13.         update james
  14.         set col02 = @counter where col = @a
  15.     end
  16.  
  17. if @a > 0
  18. begin
  19.  
  20.         while @a < @count
  21.         begin
  22.         set @counter = (select col02 from james where col = @a)
  23.         set @a = @a + 1
  24.  
  25.         set @counter2 = @counter + (select col01 from james where col = @a)
  26.         print @counter2
  27.  
  28.         update james
  29.         set col02 = @counter2 where col = @a
  30.  
  31.         end
  32. end
  33.  
Table name = james
Columns = (col, col01, col02)

Table looks like:
col col01 col02
1 50 <50>
2 100 <150>
3 150 <300>
4 200 <500>
5 250 <750>
6 300 <1050>

-----------------------------------------------------------------------
Theres prob an easier way, but this def works.
-----------------------------------------------------------------------
Nov 9 '07 #5
muddasirmunir
284 100+
thanks james
it is working fine but i it is calculat by updating table can 1 make
a view
for e-g my talbe looks like this (only two fields)

col col01
1 50
2 100
3 150
4 200
5 250
6 300

but my view looks like this (three columns)
Table looks like:
col col01 col02
1 50 <50>
2 100 <150>
3 150 <300>
4 200 <500>
5 250 <750>
6 300 <1050>

thanks in advance






Expand|Select|Wrap|Line Numbers
  1. declare @a int
  2. declare @b int
  3. declare @counter int
  4. declare @counter2 int
  5. declare @count int
  6. set @count = (select Count(*) from james)
  7. set @counter = 0
  8. set @a = (select top 1 (col) from james)
  9. set @b = (select col01 from james where col = @a) 
  10. if @a = 1
  11. begin
  12. set @counter = (@counter + @b)
  13. update james
  14. set col02 = @counter where col = @a
  15. end
  16.  
  17. if @a > 0
  18. begin
  19.  
  20. while @a < @count
  21. begin
  22. set @counter = (select col02 from james where col = @a)
  23. set @a = @a + 1
  24.  
  25. set @counter2 = @counter + (select col01 from james where col = @a)
  26. print @counter2
  27.  
  28. update james
  29. set col02 = @counter2 where col = @a
  30.  
  31. end
  32. end
  33.  
Table name = james
Columns = (col, col01, col02)

Table looks like:
col col01 col02
1 50 <50>
2 100 <150>
3 150 <300>
4 200 <500>
5 250 <750>
6 300 <1050>

-----------------------------------------------------------------------
Theres prob an easier way, but this def works.
-----------------------------------------------------------------------
Nov 9 '07 #6
jamesd0142
469 256MB
if your view has the three columns then instead of refrencing the table in the code i supplied, can you not simply reference the view you created?

sorry, i'm unable to test this myself as im on a machine that doesnt have sql server installed at present.

mayb you could make a copy of the existing table also and update the copy instead of messing up the origional???

thanks james
it is working fine but i it is calculat by updating table can 1 make
a view
thanks in advance
Nov 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stormblade | last post by:
Hey all, I have a web app that uses SQLServer 2000. I am switching to MySQL 4. 1.1. I have re-created all the tables but I'm running into 2 problems. 1. In SQLServer I can create a...
5
by: Steve | last post by:
Hi; I went to the microsoft site to try to find a guide to the error messages that the jdbc drivers give ( for sqlserver 2000 ). I had no luck. Does anyone know if there is such a guide? ...
2
by: Patrox | last post by:
Hi ! when installing sqlserver 2000 on a Windows 2003 server it explicitly tells "server not compatible with Windows 2003" during install, but it can carry on. After we applied serfice pack 3a...
0
by: williams | last post by:
I am trying to encrypt data in a SQLServer 2000 Cluster using Microsoft EFS. I have successfully encrypted a standalone DB but we are having difficulty with the Cluster. I am only encrypting the...
14
by: Roy Gourgi | last post by:
Hi, I need to store and retrieve information from a database. It looks as though there is a lot more support for SQLServer than there is for Access, correct me if I am wrong. What do I have...
0
by: Ron | last post by:
Hi there My company is developing a web based document archival and retrieval system, using ASP.NET, c# and sqlserver 2000. This development is in testing at present and all looks promising. ...
3
by: Dan Sikorsky | last post by:
Can I use SQLServer 2000 with ASP.NET 2.0 instead of SQLServer 2005, and use the .Net 2.0 Membership functionality? I've setup my Login page, controls, etc., and now it's time to use the Web...
5
by: JSParker1 | last post by:
Summary: Maximum number of records per second that can be inserted into SQLServer 2000. I am trying to insert hundreds (preferably even thousands) of records per second in to SQLServer table...
2
by: =?Utf-8?B?SmVmZnJleQ==?= | last post by:
I have some old ASP programs w/ SQLserver 2000 databases. Now I am developing ASP.NET projects using VB 2005 and SQLserver 2005. What are the best procedures to develop and test the ASP.NET...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.