8.3.08

To find Index of white spaces in SQL Server

Charindex is used to check a particular character index in a word. I tried to pick the index of the white spaces and insert those details in a temporary table. Below is the code,
Code Snippet

declare @qry varchar(100), @StartLoc int

select @StartLoc = 1

select @qry = '1 df546 156 008 10/00 1203301985
BEY 112354 PaaaP 6785.00 012300-0110 011011011080 B O '

create table #VenkatTable(val int)
while @StartLoc <= len(@Qry)
begin set @StartLoc = charindex(' ',@qry,@StartLoc)
insert into #VenkatTable values (@StartLoc)
set @StartLoc = @StartLoc+1

end

select * from #VenkatTable

drop table #VenkatTable

Regards,
Venkatesan Prabu .J

No comments:

Post a Comment