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.
| Author |
Topic |
|
daipayan
Posting Yak Master
181 Posts |
Posted - 2009-12-23 : 00:04:17
|
Hello there,I have 2 tables: Heading & RangeIn Heading, the columns are: ID, Heading, Max, MinIn Range, the columns are: ID, HeadingID, RangeNow, I want whenever I insert the data in Heading like:-------------------------ID | Heading | Max | Min-------------------------1 | ABC | 0 | 32 | XYZ | 2 | 43 | MNP | 1 | 3------------------------- Then with help of Trigger, it should update the Range table in following way:-----------------------ID | HeadingID | Range-----------------------1 | 1 | 02 | 1 | 13 | 1 | 24 | 1 | 35 | 2 | 26 | 2 | 37 | 2 | 48 | 3 | 19 | 3 | 210 | 3 | 3----------------------- Please help!Daipayan |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-23 : 00:29:45
|
| Here your TriggerCreate TRIGGER my_tgr ON Heading FOR INSERTAS BEGIN declare @min intdeclare @max intdeclare @heading intdeclare @i intselect @heading=Heading,@min=[min],@max=[max] from inserted set @i=@minwhile(@i<=@max)Begininsert into [Range](HeadingID , [Range])select @heading,@iset @i=@i+1End EndSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
daipayan
Posting Yak Master
181 Posts |
Posted - 2009-12-23 : 00:45:28
|
| Thank You Sir!Daipayan |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-23 : 00:48:25
|
quote: Originally posted by daipayan Thank You Sir!Daipayan
Welcome Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-23 : 01:53:07
|
| Which version of SQL Server are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
daipayan
Posting Yak Master
181 Posts |
Posted - 2009-12-23 : 02:00:47
|
| MS SQL 2000Daipayan |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-23 : 05:12:12
|
| [code]select headingid,range from(select number, id as headingid,case when [max]+number-1>[Min] then -1 else [max]+number-1 end as rangefrom your_table, master..spt_valueswhere type='p' and number between 1 and @total) as twhere range>-1order by 1[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|