Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating record in table

Author  Topic 

GrahameA
Starting Member

3 Posts

Posted - 2008-06-09 : 06:03:26
Hi all, I'm new to SQL and have been trying to update a record in a table, something I imagine would be quite simple. The record holds a INT value and I wish to test the value to see if it is greater than 70, if it is....reset the value to 1

I have tried various methods, aiming at using a stored procedure that will run once a day at midnight.

Any help would be great.

Abbo

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-06-09 : 06:09:54
hi pls try this

update ur_tablename set ur_columnname=1 where ur_columnname >70

ok tanx...
Go to Top of Page

GrahameA
Starting Member

3 Posts

Posted - 2008-06-09 : 07:40:46
Hi and thanks for the reply, that worked a treat... I now realise that I've not quite got it right in that what I need to do is this.

The columnname is counter and the value being added is by using the DATEDIFF fuction, counter=(select(day,startdate,GETDATE())

This returns the number of days from the stardate, if the value is greater than 70 in counter, I need some way of subtracting 70, ie if the number of days is for instance 85, then I need to subtract 70 to return the value of 15 as this number is used to get data from another table.

Sorry if this sounds confusing...

regards Abbo :-)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-09 : 14:51:44
counter=case when datediff(day,startdate,GETDATE())>70 then datediff(day,startdate,GETDATE())-70 else datediff(day,startdate,GETDATE()) end
Go to Top of Page

GrahameA
Starting Member

3 Posts

Posted - 2008-06-11 : 05:59:40
Thanks very much for the help, not in the office till next week so will try when I get in..

regards Abbo :-)
Go to Top of Page
   

- Advertisement -