Problem with SQL Query in ASP Code

Results 1 to 2 of 2

Thread: Problem with SQL Query in ASP Code

  1. #1
    Join Date
    Dec 1969

    Default Problem with SQL Query in ASP Code

    Hello all. This is driving me crazy. I have a stored procedure and some ASP code that is creating a new record if one does not exist. If the record exists it is adding to a Counter + 1. Somehow I have no idea the counter is doubling. I have tried everything. I ran the procedure on its own and it runs perfect and Counter goes to 1 on a new insert. Here is the code:<BR><BR>ASP Code:<BR>strhot = "Exec spCheckHotPart &#039;" & Trim(search_part) & "&#039;"<BR>Call Open_rs2(strhot)<BR>Call Close_rs2()<BR><BR>Stored Procedure:<BR>CREATE PROCEDURE spCheckHotPart<BR>@PARTNO varchar(24)<BR>AS<BR>Begin<BR>IF (SELECT COUNT(PART_NO) FROM HOTPART WHERE PART_NO=@PARTNO)=0<BR>INSERT INTO HOTPART(PART_NO, COUNTER, LASTACCESSED)<BR>VALUES (@PARTNO, 1, getdate())<BR>Else<BR>UPDATE HOTPART SET <BR> COUNTER=COUNTER+1,<BR> LASTACCESSED=getdate()<BR>WHERE PART_NO=@PARTNO<BR>End<BR>GO<BR><BR>If I pass a part number in Query Analyzer it works fine. If I take out the Update part in the procedure then it only inserts one row with the counter = 1. Something with the Update is like running twice in the ASP page. It is not within a loop in the page. Any idea?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Problem with SQL Query in ASP Code

    You say "counter is doubling", do you actually mean its adding 2 to the counter rather than 1 when the PARTNO already exists.<BR><BR>Your SP appears OK, the problem is may be in the line<BR>Call Open_rs2(strhot)<BR>where the SP is actually run <BR><BR>what&#039;s in this sub?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts