Wednesday, 13 January 2016

how to split string return first part and second part separately in sql server


// -- Declare variables
declare @Col1 varchar(10)='2\100'

// -- Left part
select left(@Col1,len(SUBSTRING(@Col1,0,CHARINDEX('\',@Col1))))

// -- Result 1- 2

// -- Right part
 select right(@Col1,len(SUBSTRING(@Col1,CHARINDEX('\',@Col1)+1,LEN(@Col1))))


// -- Result 2- 100

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...