Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 update field value set it old value+1 in 1 query?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  06:58:16  Show Profile
possible to do it in one query?

rs = select field from table
update field = rs(field)+1

and one advantage of stored procedure is that sp can do tasks like the one above in one db call, right?

Thanks in advance.

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 16 October 2003 :  07:28:57  Show Profile  Visit HuwR's Homepage
uhm, what exactly are you trying to do, your example does not make much sense
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  07:35:48  Show Profile
f1 : type int
ssql = "select f1 from t1 where ..."
set rs = ...

iF1 = rs("f1")
....

ssql = "update t1 set f1 = (iF1 + 1) ..."

basically, I want to update a field based on its original value, e.g. +1 or -1, and wondering if it's possible to do it in one query in asp.

I hope this time I've made myself clear
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 16 October 2003 :  07:41:26  Show Profile  Visit HuwR's Homepage
you can do that with a simple sql call,

update table set field1 = field1+1 where.....
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 16 October 2003 :  07:42:07  Show Profile
what about

update t1 set f1 = f1 + 1 where f1 = x

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  07:46:40  Show Profile
Thanks HuwR and Nikkol.

Is it possible to make sure the value is 0+ in that query? I mean, if field1 < 0 then field1 = 0?

Thanks.

Edited by - bjlt on 16 October 2003 07:48:11
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 16 October 2003 :  08:57:22  Show Profile
update t1
set f1 = case when f1<0 then 0 else f1+1 end
where ...
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  10:41:39  Show Profile
quote:

update t1
set f1 = case when f1<0 then 0 else f1+1 end
where ...



Thanks. I got a missing operator error. does it work in asp with Access as the db?

"UPDATE TABLE " &_
"SET F1 = (CASE WHEN F1 < 0 THEN 0 ELSE (F1 - 1) END)"...
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 16 October 2003 :  12:33:47  Show Profile
quote:
Originally posted by bjlt
I got a missing operator error. does it work in asp with Access as the db?


It will work in MS SQL Server, Sybase ASE and Oracle (depending on version).
I'm not sure about access.

Edited by - pweighill on 16 October 2003 12:34:16
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  12:37:57  Show Profile
I tested as an sql statement in asp on Access and got the error, guess it won't work with access. I may creat a sp for access and see if it works that way.

Thanks.
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 16 October 2003 :  12:59:48  Show Profile
well, it seems I can't creat a sp for access with those statement.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.48 seconds. Powered By: Snitz Forums 2000 Version 3.4.07