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 |
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-13 : 16:12:16
|
Hello,Is it possible with trigger to saved of system.In the tbl_table1 are saved in the column Type = 0, 1 or more...Is it possible if I have 1 in the column Type of first table to saved system Sistem 2/3, Sistem 2/4, 2/5,etc, like this:tbl_tableId, Amount1, 5 2, 103, 15with trigger to saved:Sistem 2/31 * 21 * 32 * 3?Please help. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-13 : 23:33:31
|
sorry not clear, what does 2/3 etc represent? whats your rule for determining them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 04:28:25
|
quote: Originally posted by visakh16 sorry not clear, what does 2/3 etc represent? whats your rule for determining them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Betting systems. System 2/3, System 3/4, etc. ..tbl_tableId, Amount1, 5 2, 103, 151*2 = from the first table id1*id21*3 = from the first table id1*id32*3 = from the first table id2*id3if i have more rows in the first table must multiply each data to each. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 04:51:02
|
do you mean this?select cast(t1.id as varchar(10)) + '*' + cast(t2.id as varchar(10))from table1 t1cross join table2 t2where t1.id <> t2.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 05:13:21
|
quote: Originally posted by visakh16 do you mean this?select cast(t1.id as varchar(10)) + '*' + cast(t2.id as varchar(10))from table1 t1cross join table2 t2where t1.id <> t2.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I think so.Look what I mean: |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 05:32:23
|
ok...lemme know if you need anything else------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 05:35:20
|
quote: Originally posted by visakh16 ok...lemme know if you need anything else------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Hey,yes, this I mean. Here I need your help :) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 05:50:34
|
hmm...wat else you're expecting? i thought u told posted suggestion is sufficient------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 06:07:15
|
quote: Originally posted by visakh16 hmm...wat else you're expecting? i thought u told posted suggestion is sufficient------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I meant so:tbl_table1Id,IdEvent, Event, Odds1,1, Event1, 1.502,1, Event2, 1.343,1, Event3, 1.44In this case I need to insert the table tbl_table2:Id, table1EventId, Odds1, 1, 2.01 (1*2)2, 1, 2.16 (1*3)3,1, 1.93 (2*3)thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 06:37:17
|
[code]insert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom table1 t1inner join table1 t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 09:44:35
|
quote: Originally posted by visakh16
insert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom table1 t1inner join table1 t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I tried to use this code:ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom table1 t1inner join table1 t2on t2.IdEvent = t1.IdEventand t2.id <> t1.idbut no insert in the table2? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 10:15:55
|
do you mean this?ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 11:30:44
|
quote: Originally posted by visakh16 do you mean this?ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
This code:insert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventworks, but the problem is because t1.odds * t.2odds = 1.50*1.50=2.25In this case (look print screen) be must 1.50*1.34This means that each value must be multiplied.Like this:1.50*1.34 (1*2) = 2.011.50*1.44 (1*3) = 2.161.34*1.44 (2*3) = 1.93 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 11:32:57
|
[code]ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted iinner join table1 t1on t1.IdEvent = i.IdEvent inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 11:56:04
|
quote: Originally posted by visakh16
ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted iinner join table1 t1on t1.IdEvent = i.IdEvent inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
and t2.id <> t1.id - if i delete this line works.returns:74 1 2.25 - incorrect75 1 2.01 - correct76 1 1.80 - incorrect77 1 2.16 - correct78 1 1.93 - correct79 1 2.07 - incorrectI need returns: 2.01, 2.16, 1.93 . |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 12:32:49
|
[code]ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted iinner join table1 t1on t1.IdEvent = i.IdEvent inner join table1 t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 12:55:24
|
quote: Originally posted by visakh16
ALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted iinner join table1 t1on t1.IdEvent = i.IdEvent inner join table1 t2on t2.IdEvent = t1.IdEventand t2.id <> t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
returns - no correct:94 1 2,2595 1 2,2596 1 2,0197 1 2,0198 1 1,8099 1 2,25100 1 2,01101 1 2,16102 1 2,01103 1 1,80104 1 1,93105 1 2,16106 1 1,93107 1 2,07Please create table1 and table2Structure table1:ID int UncheckedIdEvent int CheckedEvent nvarchar(50) CheckedOdds numeric(18, 2) Checkedand table2:ID int Uncheckedtable1EventId int CheckedOdds numeric(18, 2) CheckedWhen I inserted data into table in the table1 should automatically insert data in the table2I I have data in the table1:Id IdEvent Event Odds 39 1 ev1 1,5040 1 ev2 1,3441 1 ev3 1,44automatically inserts the data:Id table1EventId Odds97 1 2,01 (1.50*1.34)101 1 2,16 (1.50*1.44)104 1 1,93 (1.34*144) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 13:08:32
|
i got the problemALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id > t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 15:45:19
|
quote: Originally posted by visakh16 i got the problemALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id > t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Yes but the problem is because returns:108 1 2,25109 1 1,80110 1 2,07 |
 |
|
programer
Posting Yak Master
221 Posts |
Posted - 2011-12-14 : 18:06:45
|
quote: Originally posted by programer
quote: Originally posted by visakh16 i got the problemALTER TRIGGER Trigger4ON dbo.table1FOR INSERT /* INSERT, UPDATE, DELETE */ASinsert table2 (table1EventId,Odds)select t1.IdEvent, t1.Odds * t2.Oddsfrom inserted t1inner join inserted t2on t2.IdEvent = t1.IdEventand t2.id > t1.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Yes but the problem is because returns:108 1 2,25109 1 1,80110 1 2,07
Hello,Maybe is better understood this:table1:Id, Description1, test12, test23, test3table2:Id, table1Id, Description, RandomInt10, 1, test1, rnd111, 1, test2, rnd2---------------------------------------------Id, table1Id, Description, RandomInt10, 1, test1, rnd211, 1, test3, rnd2--------------------------------------------Id, table1Id, Description, RandomInt10, 1, test2, rnd311, 1, test3, rnd3This is example for 3 Doubles system.Why i need RandomInt? Because I be must combine the data as shown above. I hope I was clear.Help |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-15 : 00:15:34
|
nope...i didnt get what you're explaining. Can you elaborate showing results?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Next Page
|
|
|
|
|