SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Trigger Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

egemen_ates
Yak Posting Veteran

Turkey
63 Posts

Posted - 08/27/2012 :  04:14:56  Show Profile  Reply with Quote
I want to create trigger ,for this query,how can ?


SELECT
CASE WHEN BA=1 THEN SUM(TEST_ROWS.AMOUNT) ELSE 0 END AS ALACAK,
CASE WHEN BA=1 THEN SUM(ISNULL(TEST_ROWS.AMOUNT_2,0)) ELSE 0 END AS ALACAK_2,
CASE WHEN BA=0 THEN SUM(TEST_ROWS.AMOUNT) ELSE 0 END AS BORC,
CASE WHEN BA=0 THEN SUM(ISNULL(TEST_ROWS.AMOUNT_2,0)) ELSE 0 END AS BORC_2,
TEST_ROWS.ACCOUNT_ID,
TEST.ACTION_DATE,
TEST.CARD_TYPE,
TEST.CARD_CAT_ID
FROM
TEST_ROWS,TEST
WHERE
BA IN (0,1) AND TEST.CARD_ID=TEST_ROWS.CARD_ID
GROUP BY
TEST_ROWS.ACCOUNT_ID,
TEST.ACTION_DATE,
TEST.CARD_TYPE,
TEST.CARD_CAT_ID,
TEST_ROWS.BA

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 08/27/2012 :  04:31:19  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
What do you want the trigger to do and when do you want it to fire?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

egemen_ates
Yak Posting Veteran

Turkey
63 Posts

Posted - 08/27/2012 :  04:39:41  Show Profile  Reply with Quote
insert update or delete test_rows table,

quote:
Originally posted by nigelrivett

What do you want the trigger to do and when do you want it to fire?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

egemen_ates
Yak Posting Veteran

Turkey
63 Posts

Posted - 08/27/2012 :  04:43:50  Show Profile  Reply with Quote
I want to this query result into table for example CUMLATIVE TABLE,AFTER
I WANT TO CREATE TRIGGER ON TEST_ROWS AND TEST TABLE FOR UPDATE DELETE AND INSERT.THIS QUERY RESULT MUST BE SAME CUMLATIVE TABLE

quote:
Originally posted by nigelrivett

What do you want the trigger to do and when do you want it to fire?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 08/27/2012 :  04:54:05  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
That would mean a trigger on both test and test_rows.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

egemen_ates
Yak Posting Veteran

Turkey
63 Posts

Posted - 08/27/2012 :  05:03:00  Show Profile  Reply with Quote
YES
quote:
Originally posted by nigelrivett

That would mean a trigger on both test and test_rows.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 08/27/2012 :  05:55:08  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Here's one for test_rows

create trigger tr on test_rows after insert, update , delete
as
delete tbl_sum
from tbl_sum t
join (select ACCOUNT_ID from inserted union select ACCOUNT_ID from deleted) a
on a.ACCOUNT_ID t.ACCOUNT_ID

insert tbl_sum
SELECT
CASE WHEN BA=1 THEN SUM(TEST_ROWS.AMOUNT) ELSE 0 END AS ALACAK,
CASE WHEN BA=1 THEN SUM(ISNULL(TEST_ROWS.AMOUNT_2,0)) ELSE 0 END AS ALACAK_2,
CASE WHEN BA=0 THEN SUM(TEST_ROWS.AMOUNT) ELSE 0 END AS BORC,
CASE WHEN BA=0 THEN SUM(ISNULL(TEST_ROWS.AMOUNT_2,0)) ELSE 0 END AS BORC_2,
TEST_ROWS.ACCOUNT_ID,
TEST.ACTION_DATE,
TEST.CARD_TYPE,
TEST.CARD_CAT_ID
FROM
TEST_ROWS,TEST
WHERE
BA IN (0,1) AND TEST.CARD_ID=TEST_ROWS.CARD_ID
and TEST_ROWS.ACCOUNT_ID in ((select ACCOUNT_ID from inserted union select ACCOUNT_ID from deleted) )
GROUP BY
TEST_ROWS.ACCOUNT_ID,
TEST.ACTION_DATE,
TEST.CARD_TYPE,
TEST.CARD_CAT_ID,
TEST_ROWS.BA

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000