dbTalk Databases Forums  

can i increment the column (c1+2) ---by creating the trigger

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss can i increment the column (c1+2) ---by creating the trigger in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
satish
 
Posts: n/a

Default can i increment the column (c1+2) ---by creating the trigger - 03-09-2006 , 11:53 PM






hi,
i am a beginner to ms sql server2000
i have a table
create table ddd (a int, b int)
by table structure is a b
now when i enter a value in b column suppose '2' in column b
bext time when i insert a value in the column a i have to get the value
in b as 3 is thi spossible with triggers

insert into gdg values (1,2)
a b
1 2
insert into gdg (a) values(2)
a b
2 3----------------> i have to get this 3 automatically

is there any method to get this

pls help me

satish


Reply With Quote
  #2  
Old   
Jack Vamvas
 
Posts: n/a

Default Re: can i increment the column (c1+2) ---by creating the trigger - 03-10-2006 , 01:18 AM






You could try

DECLARE @lastNum INT
SET @lastNum = (SELECT TOP 1 ISNULL(b,0) + 1 FROM ddd ORDER BY b DESC)
insert into ddd (a,b)
values(2,@lastNum)


--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm

"satish" <satishkumar.gourabathina (AT) gmail (DOT) com> wrote

Quote:
hi,
i am a beginner to ms sql server2000
i have a table
create table ddd (a int, b int)
by table structure is a b
now when i enter a value in b column suppose '2' in column b
bext time when i insert a value in the column a i have to get the value
in b as 3 is thi spossible with triggers

insert into gdg values (1,2)
a b
1 2
insert into gdg (a) values(2)
a b
2 3----------------> i have to get this 3 automatically

is there any method to get this

pls help me

satish




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.