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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to increase a field value according to another

Author  Topic 

oneforall2012
Starting Member

4 Posts

Posted - 2008-02-07 : 03:07:14
Hello there
i have a Table with tow fields(book,row),both fields are integers
book field is Identity Increment
now i want to increase row value by 1 when book values became 25
here is an example

Book -- Row
1 1
2 1
3 1
4 1
.
.
25 1
26 2
now you see that when Book became 26 , Row raised by 1 and became 2
any ideas
thnx

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-07 : 03:46:50
UPDATE Table
SET Row = 1 + Book / 26



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

oneforall2012
Starting Member

4 Posts

Posted - 2008-02-07 : 04:40:44
thnx Peso
but i need this when i am going to insert the new record
thnx
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-07 : 04:47:48
INSERT Table
VALUES (-1)

UPDATE Table
SET Row = Book / 26
WHERE Row = 0



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-07 : 04:51:31
Or create a INSERT trigger?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

oneforall2012
Starting Member

4 Posts

Posted - 2008-02-07 : 05:48:00
i found the soluation of this matter
i have to make the row field computed
and type the folowing in the Formula

convert(int,Book/25)

thnx Peso for your help
Salam
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-07 : 06:16:29
How are you going to insert a value to this table?
DECLARE	@Test1 TABLE (Book INT IDENTITY(1, 1) PRIMARY KEY, Row AS (1 + Book / 25))

SELECT *
FROM @Test1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -