a l t e r   p r o c   p r c K a r k a r d V i s i t o r   @ p c o d e   b i g i n t , @ f c I d   i n t , @ o r g I d   i n t , @ f r o m D a t e   i n t , @ t o D a t e   i n t ,   @ f r o m P r i c e   d e c i m a l ( 1 9 , 4 ) ,   @ t o P r i c e   d e c i m a l ( 1 9 , 4 ) , @ k a l I d   i n t , @ p r o I d G r o o h K a l a   i n t   a s 
 
 b e g i n 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   HJ2J*H1J  /1  *  *  'D'G'| ./E'*  (3*'F'1
 
 s e l e c t 
 
 	 m . I D   [ I D ] , 
 
 	 m . C o d e   [ C o d e ] , 
 
 	 m . t a r i k h   [ T a r i k h ] , 
 
 	 c a s e   m . D o m _ I D _ N o e 
 
 	 	 w h e n   2 8   t h e n - -   ' HJ2J*H1J  A'*H1  A1H4
 
 	 	 	 c a s e   d . D o m _ I D _ N o e 
 
 	 	 	 	 w h e n   6 6 7   t h e n   - -   K h a d a m a t 
 
 	 	 	 	 	 ' HJ2J*H1J  A1H4  ( ' +   c a s t (   m . C o d e     a s   n v a r c h a r )   +   ' )   F'E  ./E'*  : ' + ( s e l e c t   t t . T i t l e   + ' ( ' +   c a s t   ( t t . C o d e     a s   n v a r c h a r ) + ' ) '   f r o m   t a f s i l i   t t   w h e r e   t t . I D   =   d . T a f _ I D _ K h a d a m a t ) 
 
 	 	 	 	 w h e n   6 6 6   t h e n   - - K a l a 
 
 	 	 	 	 	 ' HJ2J*H1J  A1H4  ( ' +   c a s t (   m . C o d e     a s   n v a r c h a r )   +   ' )   F'E  'D'  : '   +   ( s e l e c t   k k . n a m e   + ' ( ' +   c a s t   ( k k . C o d e     a s   n v a r c h a r ) + ' ) '   f r o m   K a l a   k k   w h e r e   k k . I D   =   d . K a l _ I D )   e n d 
 
 	 	 	 	 
 
 	 	 w h e n   3 1   t h e n   - - ' HJ2J*H1J  .1J/  
 
 	 	 	 c a s e   d . D o m _ I D _ N o e 
 
 	 	 	 	 w h e n   6 6 6   t h e n   - - K a l a 
 
 	 	 	 	 	 ' HJ2J*H1J  .1J/  ( ' +   c a s t (   m . C o d e     a s   n v a r c h a r )   +   ' )   F'E  'D'  : '   +   ( s e l e c t   k k . n a m e   + ' ( ' +   c a s t   ( k k . C o d e     a s   n v a r c h a r ) + ' ) '   f r o m   K a l a   k k   w h e r e   k k . I D   =   d . K a l _ I D )   e n d 
 
 	 e n d   a s   [ S h a r h ] , 
 
 	 m . T a f _ I D _ M o s h t a r i   [ T a f _ I D _ M o s h t a r i ] , 
 
 	 t a f . C o d e   [ T a f _ C o d e _ M o s h t a r i ] , 
 
 	 t a f . T i t l e   [ T a f _ T i t l e _ M o s h t a r i ] , 
 
 	 d . m a b l a g h   [ F i ] , 
 
 	 d . t e d a d   [ T e d a d ] , 
 
 	 
 
 	 c a s e   m . D o m _ I D _ n o e 
 
 	 	 w h e n   2 8   t h e n   - -   F o r o o s h 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d   -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 	 w h e n   3 1   t h e n   - -   K h a r i d 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d     -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   - 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 e n d   a s   [ M a b l a g h F a c t o r ] , 
 
 	 d . M a b l a g h e T a k h f i f [ M a b l a g h T a k h f i f ] , 
 
 	 d . D a r s a d e V i s i t o r [ D a r s a d V i s i t o r ] , 
 
 	 d . M a b l a g h e V i s i t o r   [ M a b l a g h e V i s i t o r ] , 
 
 	 0 . 0 [ M a b l a g h V i s i t o r B e d e h K a r ] , 
 
 	 d . M a b l a g h e V i s i t o r [ M a b l a g h V i s i t o r B e s t a n K a r ] , 
 
 	 c a s e   m . D o m _ I D _ n o e 
 
 	 	 w h e n   2 8   t h e n   1 2   - - F o r o o s h 
 
 	 	 w h e n   3 1   t h e n   1 3   - -   K h a r i d 
 
 	 e n d   a s   [ N o e R a d i f ] , 
 
 	 m . k a r _ I D   [ K a r _ I D _ C r e a t o r ] , 
 
 	 d . K a l _ I D   [ K a l _ I D ] , 
 
 	 k . C o d e   [ K a l _ C o d e ] , 
 
 	 k . N a m e   [ K a l _ T i t l e ] , 
 
 	 s . c o d e   [ T a f _ C o d e _ S e r v i c e ] , 
 
 	 s . T i t l e   [ T a f _ T i t l e _ S e r v i c e ] , 
 
 	 c r e a t o r . T i t l e   [ K a r _ T i t l e _ C r e a t o r ] , 
 
 	 i s n u l l ( k . P r o _ I D _ G r o o h , 0 )   [ P r o _ I D _ G r o o h K a l a ] 
 
 f r o m   B a r g e h   m   
 
 	 j o i n   B a r g e h D e t a i l   d   o n   m . I D   =   d . B a r _ I D   
 
 	 j o i n   T a f s i l i   t a f   o n   m . T a f _ I D _ M o s h t a r i   =   t a f . I D 
 
 	 i n n e r   j o i n   K a r b a r   k a r   o n   m . K a r _ I D   =   k a r . I D 
 
 	 i n n e r   j o i n   T a f s i l i   c r e a t o r   o n   k a r . T a f _ I D   =   c r e a t o r . I D 
 
 	 l e f t   j o i n   K a l a   k   o n   d . K a l _ I D   =   k . I D 
 
 	 l e f t   j o i n   T a f s i l i   s   o n   d . T a f _ I D _ K h a d a m a t   =   s . I D 
 
 w h e r e   
 
 	 m . D o m _ I D _ V a z i a t   ! =   1 0 1   a n d   
 
 	 d . T a f _ I D _ V i s i t o r   i s   n o t   n u l l   a n d 
 
 	 m . D o m _ I D _ n o e   i n   ( 2 8 , 3 1 )   a n d   - -   K h a r i d   ,   F o r o o s h 
 
 	 d . T a f _ I D _ V i s i t o r   =   @ p c o d e   a n d 
 
 	 ( @ f c I d   =   0   o r   m . F C _ I D   =   @ f c I d )   a n d 
 
 	 ( @ o r g I d   =   0   o r   m . P r o _ I D _ V a h e d M a l i   =   @ o r g I d )   a n d 
 
 	 ( @ f r o m D a t e   =   0   o r   m . T a r i k h   > =   @ f r o m D a t e )   a n d 
 
 	 ( @ t o D a t e   =   0   o r   m . T a r i k h   < =   @ t o D a t e )   a n d 
 
 	 ( @ f r o m P r i c e   =   0   o r   i s n u l l ( d . M a b l a g h e V i s i t o r , 0 )   > =   @ f r o m P r i c e )   a n d 
 
 	 ( @ t o P r i c e   =   0   o r   i s n u l l ( d . M a b l a g h e V i s i t o r , 0 )   < =   @ t o P r i c e )   a n d 
 
 	 ( @ k a l I d   =   0   o r   i s n u l l ( d . K a l _ I D , 0 )   =   @ k a l I d )   a n d 
 
 	 ( @ p r o I d G r o o h K a l a   =   0   o r   i s n u l l ( k . P r o _ I D _ G r o o h , 0 )   =   @ p r o I d G r o o h K a l a ) 
 
 - - - - - - - - - - - 
 
 u n i o n   a l l 
 
 - - - - - - - - - - - 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   HJ2J*H1J  /1  *  *  'D'G'  (/G'1
 
 s e l e c t 
 
 	 m . I D   , 
 
 	 m . C o d e   , 
 
 	 m . t a r i k h , 
 
 	 c a s e   m . D o m _ I D _ N o e 
 
 	 	 w h e n   2 9   t h e n   - - ' HJ2J*H1J  (14*  '2  A1H4  
 
 	 	 	 c a s e   d . D o m _ I D _ N o e 
 
 	 	 	 	 w h e n   6 6 6   t h e n   - - K a l a 
 
 	 	 	 	 	 ' HJ2J*H1J  (14*  '2  A1H4  ( ' +   c a s t (   m . C o d e     a s   n v a r c h a r )   +   ' )   F'E  'D'  : '   +   ( s e l e c t   n a m e   + ' ( ' +   c a s t   ( C o d e     a s   n v a r c h a r ) + ' ) '   f r o m   K a l a   w h e r e   I D   =   d . K a l _ I D )   e n d 
 
 	 	 w h e n   3 2   t h e n   - - ' HJ2J*H1J  (14*  '2  .1/  
 
 	 	 	 c a s e   d . D o m _ I D _ N o e 
 
 	 	 	 	 w h e n   6 6 6   t h e n   - - K a l a 
 
 	 	 	 	 	 ' HJ2J*H1J  (14*  '2  .1/    ( ' +   c a s t (   m . C o d e     a s   n v a r c h a r )   +   ' )   F'E  'D'  : '   +   ( s e l e c t   n a m e   + ' ( ' +   c a s t   ( C o d e     a s   n v a r c h a r ) + ' ) '   f r o m   K a l a   w h e r e   I D   =   d . K a l _ I D )   e n d 
 
 
 
 	 e n d   , 
 
 	 m . T a f _ I D _ M o s h t a r i , 
 
 	 t a f . C o d e   , 
 
 	 t a f . T i t l e   , 
 
 	 d . m a b l a g h , 
 
 	 d . t e d a d , 
 
 	 
 
 	 c a s e   m . D o m _ I D _ n o e 
 
 	 	 w h e n   2 9   t h e n   - -   B a r g a s h t A z F o r o o s h 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d     -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   
 
 	 	 w h e n   3 2   t h e n   - -   B a r g a s h A z K h a r i d 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d   -   i s n u l l ( d . M a b l a g h e T a k h f i f , 0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ n o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   m . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 e n d   , 
 
 	 d . M a b l a g h e T a k h f i f , 
 
 	 d . D a r s a d e V i s i t o r , 
 
 	 d . M a b l a g h e V i s i t o r   , 
 
 	 d . M a b l a g h e V i s i t o r , 
 
 	 0 . 0 , 
 
 	 c a s e   m . D o m _ I D _ n o e 
 
 	 	 w h e n   2 9   t h e n   1 5   - -   B a r g a s h t A z F o r o o s h 
 
 	 	 w h e n   3 2   t h e n   1 4   - -   B a r g a s h t A z K h a r i d 
 
 	 e n d   , 
 
 	 m . K a r _ I D   , 
 
 	 d . K a l _ I D   , 
 
 	 k . C o d e   , 
 
 	 k . N a m e   , 
 
 	 s . c o d e , 
 
 	 s . T i t l e , 
 
 	 c r e a t o r . T i t l e , 
 
 	 i s n u l l ( k . P r o _ I D _ G r o o h , 0 ) 
 
 f r o m   B a r g e h   m   
 
 	 j o i n   B a r g e h D e t a i l   d   o n   m . I D   =   d . B a r _ I D   
 
 	 j o i n   T a f s i l i   t a f   o n   m . T a f _ I D _ M o s h t a r i   =   t a f . I D 
 
 	 i n n e r   j o i n   K a r b a r   k a r   o n   m . K a r _ I D   =   k a r . I D 
 
 	 i n n e r   j o i n   T a f s i l i   c r e a t o r   o n   k a r . T a f _ I D   =   c r e a t o r . I D 
 
 	 l e f t   j o i n   K a l a   k   o n   d . K a l _ I D   =   k . I D 
 
 	 l e f t   j o i n   T a f s i l i   s   o n   d . T a f _ I D _ K h a d a m a t   =   s . I D 
 
 w h e r e   
 
 	 m . D o m _ I D _ V a z i a t   ! =   1 0 1   a n d   
 
 	 d . T a f _ I D _ V i s i t o r   i s   n o t   n u l l   a n d 
 
 	 m . D o m _ I D _ N o e   i n   ( 2 9 , 3 2 )   a n d   - -   B a r g a s h A z K h a r i d   ,   B a r g a s h A z F o r o o s h 
 
 	 d . T a f _ I D _ V i s i t o r   =   @ p c o d e   a n d 
 
 	 ( @ f c I d   =   0   o r   m . F C _ I D   =   @ f c I d )   a n d 
 
 	 ( @ o r g I d   =   0   o r   m . P r o _ I D _ V a h e d M a l i   =   @ o r g I d )   a n d 
 
 	 ( @ f r o m D a t e   =   0   o r   m . T a r i k h   > =   @ f r o m D a t e )   a n d 
 
 	 ( @ t o D a t e   =   0   o r   m . T a r i k h   < =   @ t o D a t e )   a n d 
 
 	 ( @ f r o m P r i c e   =   0   o r   i s n u l l ( d . M a b l a g h e V i s i t o r , 0 )   > =   @ f r o m P r i c e )   a n d 
 
 	 ( @ t o P r i c e   =   0   o r   i s n u l l ( d . M a b l a g h e V i s i t o r , 0 )   < =   @ t o P r i c e )   a n d 
 
 	 ( @ k a l I d   =   0   o r   i s n u l l ( d . K a l _ I D , 0 )   =   @ k a l I d )   a n d 
 
 	 ( @ p r o I d G r o o h K a l a   =   0   o r   i s n u l l ( k . P r o _ I D _ G r o o h , 0 )   =   @ p r o I d G r o o h K a l a ) 
 
 - - - - - - - - - - - 
 
 u n i o n   a l l 
 
 - - - - - - - - - - - 
 
 s e l e c t     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   HJ2J*H1J  D  A'*H1  (3*'F'1
 
 	 b . I D   , 
 
 	 b . C o d e   , 
 
 	 b . T a r i k h , 
 
 	 c a s e   b . D o m _ I D _ N o e 
 
 	 	 w h e n   2 8   t h e n   ' HJ2J*H1J  FG'  A'*H1  A1H4  ( '   +   c a s t (   b . C o d e     a s   n v a r c h a r )   +   ' ) ' 
 
 	 	 w h e n   3 1   t h e n   ' HJ2J*H1J  FG'  A'*H1  .1/  ( '   +   c a s t (   b . C o d e     a s   n v a r c h a r )   +   ' ) ' 
 
 	 e n d   , 
 
 	 b . T a f _ I D _ M o s h t a r i , 
 
 	 t a f . C o d e   , 
 
 	 t a f . T i t l e   , 
 
 	 0 , 
 
 	 0 , 
 
 	 c a s e   b . D o m _ I D _ n o e 
 
 	 	 w h e n   2 8   t h e n   - -   F o r o o s h 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d   -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ v a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 	 w h e n   3 1   t h e n   - -   K h a r i d 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d     -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 e n d   , 
 
 	 0 . 0 , 
 
 	 b . D a r s a d e V i s i t o r , 
 
 	 b . M a b l a g h e V i s i t o r   , 
 
 	 0 . 0   , 
 
 	 b . M a b l a g h e V i s i t o r , 
 
 	 c a s e   b . D o m _ I D _ N o e 
 
 	 	 w h e n   2 8   t h e n   1 2   - - F o r o o s h 
 
 	 	 w h e n   3 1   t h e n   1 3   - -   K h a r i d 
 
 	 e n d   , 
 
 	 b . k a r _ I D   , 
 
 	 0 , 
 
 	 ' ' , 
 
 	 ' ' , 
 
 	 n u l l , 
 
 	 ' ' , 
 
 	 c r e a t o r . T i t l e , 
 
 	 0 
 
 f r o m   B a r g e h   b 
 
 	 j o i n   T a f s i l i   t a f   o n   b . T a f _ I D _ M o s h t a r i   =   t a f . I D 
 
 	 i n n e r   j o i n   K a r b a r   k a r   o n   b . K a r _ I D   =   k a r . I D 
 
 	 i n n e r   j o i n   T a f s i l i   c r e a t o r   o n   k a r . T a f _ I D   =   c r e a t o r . I D 
 
 w h e r e 
 
 	 b . D o m _ I D _ V a z i a t   ! =   1 0 1   a n d   
 
 	 - - b . n o e   n o t   i n   ( 2 , 5 ) / * P i s h F a c t o r F o r o o s h   ,   P i s h F a c t o r K h a r i d * /   a n d 
 
 	 b . T a f _ I D _ V i s i t o r   i s   n o t   n u l l   a n d 
 
 	 b . D o m _ I D _ N o e   i n   ( 2 8 , 3 1 )   a n d - -   K h a r i d   ,   F o r o o s h 
 
 	 b . T a f _ I D _ V i s i t o r   =   @ p c o d e   a n d 
 
 	 ( @ f c I d   =   0   o r   b . F C _ I D   =   @ f c I d )   a n d 
 
 	 ( @ o r g I d   =   0   o r   b . P r o _ I D _ V a h e d M a l i   =   @ o r g I d )   a n d 
 
 	 ( @ f r o m D a t e   =   0   o r   b . T a r i k h   > =   @ f r o m D a t e )   a n d 
 
 	 ( @ t o D a t e   =   0   o r   b . T a r i k h   < =   @ t o D a t e )   a n d 
 
 	 ( @ f r o m P r i c e   =   0   o r   i s n u l l ( b . M a b l a g h e V i s i t o r , 0 )   > =   @ f r o m P r i c e )   a n d 
 
 	 ( @ t o P r i c e   =   0   o r   i s n u l l ( b . M a b l a g h e V i s i t o r , 0 )   < =   @ t o P r i c e ) 
 
 - - - - - - - - - - - 
 
 u n i o n   a l l 
 
 - - - - - - - - - - - 
 
 s e l e c t     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   HJ2J*H1J  D  A'*H1  (/G'1
 
 	 b . I D   , 
 
 	 b . C o d e   , 
 
 	 b . T a r i k h [ t a r i k h ] , 
 
 	 c a s e   b . D o m _ I D _ N o e 
 
 	 	 w h e n   2 9   t h e n   ' HJ2J*H1J  FG'  A'*H1  (14*  '2  A1H4  ( '   +   c a s t (   b . C o d e     a s   n v a r c h a r )   +   ' ) ' 
 
 	 	 w h e n   3 2   t h e n   ' HJ2J*H1J  FG'  A'*H1  (14*  '2  .1/  ( '   +   c a s t (   b . C o d e     a s   n v a r c h a r )   +   ' ) ' 
 
 	 e n d   , 
 
 	 b . T a f _ I D _ M o s h t a r i   , 
 
 	 t a f . C o d e   , 
 
 	 t a f . T i t l e   , 
 
 	 0 , 
 
 	 0 , 
 
 	 c a s e   b . D o m _ I D _ n o e 
 
 	 	 w h e n   2 9   t h e n   - -   B a r g a s h t A z F o r o o s h 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d     -   i s n u l l ( d . M a b l a g h e T a k h f i f   ,   0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 	 w h e n   3 2   t h e n   - -   B a r g a s h A z K h a r i d 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h   *   d . M e g h d a r 1   *   d . M e g h d a r 2   *   d . t e d a d   -   i s n u l l ( d . M a b l a g h e T a k h f i f , 0 ) ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   -   
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 0   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . m a b l a g h ) 
 
 	 	 	 	 f r o m   D a r y a f t P a r d a k h t   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D 	   a n d 
 
 	 	 	 	 d . D o m _ I D _ N o e M a s t e r   =   4 2   a n d 
 
 	 	 	 	 d . D o m _ I D _ V a z i a t   ! =   1 0 1 )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 )   + 
 
 	 	 	 i s n u l l 
 
 	 	 	 ( 
 
 	 	 	 	 c a s t ( ( s e l e c t   s u m ( d . M a b l a g h A r z e s h A f z o o d e h ) 
 
 	 	 	 	 f r o m   B a r g e h D e t a i l   d 
 
 	 	 	 	 w h e r e   d . B a r _ I D   =   b . I D )   a s   d e c i m a l ( 1 9 , 4 ) ) 
 
 	 	 	 , 0 . 0 ) 
 
 	 e n d   , 
 
 	 0 . 0 , 
 
 	 b . D a r s a d e V i s i t o r , 
 
 	 b . M a b l a g h e V i s i t o r   , 
 
 	 b . M a b l a g h e V i s i t o r   , 
 
 	 0 . 0   , 
 
 	 c a s e   b . D o m _ I D _ N o e 
 
 	 	 w h e n   2 9   t h e n   1 5   - -   B a r g a s h t A z F o r o o s h 
 
 	 	 w h e n   3 2   t h e n   1 4   - -   B a r g a s h t A z K h a r i d 
 
 	 e n d   , 
 
 	 b . K a r _ I D   , 
 
 	 0   , 
 
 	 ' ' , 
 
 	 ' ' , 
 
 	 n u l l , 
 
 	 ' ' , 
 
 	 c r e a t o r . T i t l e , 
 
 	 0 
 
 f r o m   B a r g e h   b 
 
 	 j o i n   T a f s i l i   t a f   o n   b . T a f _ I D _ M o s h t a r i   =   t a f . I D 
 
 	 i n n e r   j o i n   K a r b a r   k a r   o n   b . K a r _ I D   =   k a r . I D 
 
 	 i n n e r   j o i n   T a f s i l i   c r e a t o r   o n   k a r . T a f _ I D   =   c r e a t o r . I D 
 
 w h e r e 
 
 	 b . D o m _ I D _ V a z i a t   ! =   1 0 1   a n d   
 
 	 b . T a f _ I D _ V i s i t o r   i s   n o t   n u l l   a n d 
 
 	 b . D o m _ I D _ N o e   i n   ( 2 9 , 3 2 )   a n d   - -   B a r g a s h t A z K h a r i d   ,   B a r g a s h t A z F o r o o s h 
 
 	 b . T a f _ I D _ V i s i t o r   =   @ p c o d e   a n d 
 
 	 ( @ f c I d   =   0   o r   b . F C _ I D   =   @ f c I d )   a n d 
 
 	 ( @ o r g I d   =   0   o r   b . P r o _ I D _ V a h e d M a l i   =   @ o r g I d )   a n d 
 
 	 ( @ f r o m D a t e   =   0   o r   b . T a r i k h   > =   @ f r o m D a t e )   a n d 
 
 	 ( @ t o D a t e   =   0   o r   b . T a r i k h   < =   @ t o D a t e )   a n d 
 
 	 ( @ f r o m P r i c e   =   0   o r   i s n u l l ( b . M a b l a g h e V i s i t o r , 0 )   > =   @ f r o m P r i c e )   a n d 
 
 	 ( @ t o P r i c e   =   0   o r   i s n u l l ( b . M a b l a g h e V i s i t o r , 0 )   < =   @ t o P r i c e ) 
 
 
 
 o r d e r   b y   T a r i k h 
 
 e n d 