/*
Mobile phone activity statistics
*/
Create Proc Usp_actioncount
@ Planid Int ,
@ Updatetype Varchar ( 50 )
As
-- ------------------------------------------------------------------
Create Table # Tempa (
ID Int Identity ( 1 , 1 ) Not Null ,
Mobile Varchar ( 20 ) Not Null ,
Updatetype Varchar ( 50 )
)
Create Table # Tempb (
ID Int Identity ( 1 , 1 ) Not Null ,
Mobile Varchar ( 20 ) Not Null ,
Updatetype Varchar ( 20 )
)
Insert Into # Tempa (mobile, updatetype) Select Distinct Msisdn, '' From Tb_planmsisdn Where Plan_id = @ Planid
Declare @ ID Int , @ Mobile Varchar ( 20 )
Select @ ID = Count ( 1 ) From # Tempa Ta
While @ ID > 0
Begin
Select @ Mobile = Mobile From # Tempa Ta Where Ta. ID = @ ID
Truncate Table # Tempb
Insert Into # Tempb (mobile, updatetype) Select Distinct Msisdn, updatetype From Tb_planmsisdn TPM Where TPM. msisdn = @ Mobile And TPM. plan_id = @ Planid
Declare @ Innerid Int , @ Utype Varchar ( 20 ), @ Innermobile Varchar ( 20 )
Select @ Innerid = Count ( 1 ) From # Tempb TB
While @ Innerid > 0
Begin
Select @ Utype = Updatetype, @ Innermobile = TB. Mobile From # Tempb TB Where TB. ID = @ Innerid
If Charindex ( @ Utype , @ Updatetype ) > 0
Begin
Update # Tempa Set Updatetype = Updatetype + Case @ Utype
When ' 1 ' Then ' Periodic update '
When ' 2 ' Then ' Shutdown '
When ' 3 ' Then ' Start '
When ' 4 ' Then ' Enter the residential area '
When ' 5 ' Then ' Paging response '
When ' 6 ' Then ' Text message '
When ' 7 ' Then ' Caller '
When ' 8 ' Then ' SMS receiving '
Else ''
End Where Mobile = @ Innermobile
End
Set @ Innerid = @ Innerid - 1
End
Set @ ID = @ ID - 1
End
Select * From # Tempa Ta
Drop Table # Tempb
Drop Table # Tempa
Go