Monday, March 26, 2012

If @@Rowcount = .... problem

Hello again everyone....

Ok here's my problem... This is definetly the strangest problem Ive had yet in my coding career.... anyways here it is:

I have a stored procedure which keeps a total number of hits for specific pages:


Procedure CMRC_Hits_Pages_Temp_Update
@.Transaction nvarchar(20),
@.Hits int = NULL,
@.Page nvarchar(50) = NULL
AS

IF @.Transaction = 'Delete'
BEGIN

DELETE FROM CMRC_Hits_Pages_Temp

END

IF @.Transaction = 'Add'
BEGIN

CREATE TABLE #TempTableUpdate
(
Hits int
)
INSERT INTO #TempTableUpdate
(
Hits
)
SELECT
Hits
FROM
CMRC_Hits_Pages_Details
WHERE
Page = @.Page
SELECT
Hits
FROM
#TempTableUpdate

IF @.@.Rowcount > 0
BEGIN

UPDATE CMRC_Hits_Pages_Temp
SET
Hits = Hits + @.Hits
WHERE
Page = @.Page

END

IF @.@.Rowcount < 1
BEGIN

INSERT INTO CMRC_Hits_Pages_Temp
(
Hits,
Page
)
VALUES
(
@.Hits,
@.Page
)

END

END

I've written it so if there hasn't been an entry for @.Page, make a new one.... And if there is an entry allready for @.Page, add @.Hits to Hits.

Here's the strange part. When I run it in Query Analyzer (so I know there isn't a problem with my pages code), it works fine when I send @.Page a value of 'Default' (As in my default page). But when I put any other value (ei. 'ProductsList', ProductDetails', 'test', 'Defauls') it doesn't work. It creates a new record even if there was a record for that page allready. I've tried erasing everything from the table over and over to give it a fresh start and it still only works for 'Default.'

I've tried every length of string possible thinking it may be the length, same problem.

It makes no sense to me why specific letters could make any difference in what this procedure does. A string is a string, right? Why should one string be more recognizable than another? Again, the most confusing thing I've enountered yet in my coding career.

I seem to always run into problems and think "this makes no sense" and then come to figure "Ohhh... thats whats wrong..." But this problem here is definetely the cream... It makes NO sense....

Thank you to whomever can solve this mystery.... (If it is much of one...)

Just incase the Table info is important:

I have two Columns: Hits, int (4) & Page, nvarchar (50)

-AlecSorry, if you took your time to read this problem, but I figured it out.....

Again, sorry if you read that long story...

Thank you though for your time anyways...

-Alec|||... ok what was the problem again? and what was the solution?

No comments:

Post a Comment