SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 17th, 2005, 12:44 AM
ksragesh ksragesh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Chennai
Posts: 2 ksragesh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Arrow value addition while executing an update statement

Hi,

I have a small problem in sql here. I have three sql statements. My table "OrderBooks" contains fields 'Sno','Title','Author',
'Publisher','CopiesOrdered', 'CopiesRecd','OrderDate' etc.

My module in asp aims at updating the stock level everytime i receive a batch of books ordered. The problem i'm facing is something unique. Every time i try to update the stocklevel the value gets added twice. Duplication occurs only in the copiesrecd field and not the records.

My problem is discussed below:

Suppose i have ordered 50 copies of a book. And assume i have already recieved 10 copies against that order and now if i receive another set of 10 copies my table should show 20 units after the execution of the update statement

But what happens is, even before the execution of the update statement my query1 returns the value 20 and again as per the update command another 10 is added and the final query returns the value 30

I do not understand how my select query returns 20 instead of 10.

If i comment the second query then my select statements returns the correct value.


Pls refer my sql statment below
---------------------------------------------------------------
sql = "Select * from orderbooks where orderno = " & ordno
Response.Write sql
rs.Open sql,cn,3,3
Response.Write "No of copies. in table before the execution of update statement = " & rs("Copiesrecd")
Response.Write "<br>"
sql2 = "UPDATE ORDERBOOKS SET COPIESRECD =(SELECT COPIESRECD FROM ORDERBOOKS WHERE ORDERNO = " & ordno & ")+ " & qtyrecdnow & " WHERE (ORDERNO = " & ordno & ")"
rs2.Open sql2,cn,3,3
Response.Write "Update Query executed"
Response.Write "<br>"

sql3 = "Select * from orderbooks where orderno = " & ordno
Response.Write sql3
rs3.Open sql3,cn,3,3
Response.Write "No of copies. in table before the execution of update statement = " & rs3("Copiesrecd")
Response.Write "<br>"
---------------------------------------------------------------

Has anybody faced a similar problem before. If so what was the reason for the same

rgds

Ragesh

Reply With Quote
  #2  
Old February 11th, 2005, 09:16 AM
asmoran asmoran is offline
ASPFree Know-It-All
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 931 asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 16 h 6 sec
Reputation Power: 325
Hopefully you've already solved this problem (since you posted it on the 17th of Jan) but just in case:



From the looks of your code, the problem appears to be in the variable "qtyrecdnow". What exactly does this variable contain?
Sticking with your example, this variable should contain 10. You've already recieved 10 books, and you're now recieving 10 more.

The problem you're having (as well as your variable name) leads me to believe that you're storing the total you have recieved in "qtyrecdnow". So you've already recieved 10, and you're telling it that you've recieved 20. Your insert statement takes the 10 you already had, adds the 20 that you gave it, and gives you 30.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > value addition while executing an update statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT