Wednesday, 31 January 2018

SQL CharIndex Example

  1. DECLARE @PW_MPID NVARCHAR(max)  
  2. set @PW_MPID='1555|2555|35|'  
  3.   
  4. DECLARE @PW_MPIDPostion Varchar(max) = CHARINDEX('|',@PW_MPID)                                                                                      
  5. rint @PW_MPIDPostion                                                       
  6. DECLARE @TempPW_MPID Varchar(max)                                                                                          
  7. WHILE(@PW_MPIDPostion > 0)                                                   
  8.          BEGIN                          
  9.                SET @TempPW_MPID = SUBSTRING(@PW_MPID ,1,@PW_MPIDPostion-1)       
  10.                print @TempPW_MPID  
  11.                  
  12.                 SET @PW_MPID =SUBSTRING(@PW_MPID,@PW_MPIDPostion +1,LEN(@PW_MPID))                                                     
  13.                       print @PW_MPID                                                                     
  14.    SET @PW_MPIDPostion  = CHARINDEX('|',@PW_MPID)     
  15.    print @PW_MPIDPostion                                        
  16.  END   

No comments:

Post a Comment

Find Largest Element of an Array using Function in Python

# Find Largest Element of an Array using Function # python function to find maximum # in arr[] of size n def largest(arr,n): # Initi...