April 5, 2011 at 1:21 am
Dear All,
I am facing a problem in creation of trigger. Am having 2 tables named as:
Availability
-------------------
ID | Name | Status
-------------------
1 | John | 1
2 | Lama | 0
3 | Anny | 0
-------------------
User_Available
----------
ID | Name
----------
1 | Lama
2 | Anny
----------
I want to write a trigger, where it'll check the Status from Availability as 0 and update the User_Available table. This is simple Query:
Create Trigger.....
select top 1 Name from Availability where Status = 0
..END
But if the situation comes that all the Names' status is 1, then trigger should insert Name in User_Available according to the Ascending Order of the ID.
E.g.: If all status is 1 in Availability, then John name should be updated as his ID is 1 and in ascending order.
Availability
-------------------
ID | Name | Status
-------------------
1 | John | 1
2 | Lama | 1
3 | Anny | 1
-------------------
User_Available
----------
ID | Name
----------
1 | John
----------
Hope I can make you understand my query?
Regards,
Daipayan
Software Programmer
April 5, 2011 at 10:29 pm
So... let's say that everyone has a Status of 1 and you suddenly insert 100 rows. Do you want John to have all 100 rows?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 5, 2011 at 10:31 pm
Also, you need to explain which table you want the trigger on and what you want to fire it.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 5, 2011 at 10:40 pm
Dear Jeff Moden,
I skip this thought of inserting 100rows at a time..:crying:
And I'll be firing the same from a TABLE name as USER_PROBLEM:
---------------------------
ID | USERNAME | PROBLEM
---------------------------
1 | USER1 | xyz
2 | USER2 | pqr
---------------------------
April 6, 2011 at 6:48 am
mail2payan (4/5/2011)
Dear Jeff Moden,I skip this thought of inserting 100rows at a time..:crying:
And I'll be firing the same from a TABLE name as USER_PROBLEM:
---------------------------
ID | USERNAME | PROBLEM
---------------------------
1 | USER1 | xyz
2 | USER2 | pqr
---------------------------
1) Not dealing with MULTIPLE ROW updates is a VERY common problem in trigger coding - and a CRITICAL flaw.
2) May I ask if this is a homework problem?
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 6, 2011 at 6:56 am
No..not a homework. I am preparing a HelpDesk Solution for my Company..where they want to assign the call logs (by End-User) automatically to the Hardware Engineers according to their status (free/busy and if busy, then allocate according to alphabetical order).
Now I don't know how to do this automate process...:(
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply