Rajesh S

Rajesh S

  • NA
  • 110
  • 39.9k

Assign Tab delimite to variable in sql

Mar 3 2011 5:14 AM
Hi friends
 Now we look into how tab delimit assign to variable in sqlserver.
 
 Declare @tab char(1)
 set @tab=char(9)
 or
 Declare @tab nchar(1)
 set @tab=nchar(9)

  now you can check tab space using @tab variable for example

 declare @str varchar(50)
 set @str='hai  how  are  you'
 declare @tab char(9)
 declare @len int 
 set @tab=char(9)
 set @len=len(@str)
 if ((@len-len(replace(@str,@tab,'')))>0)
 begin
  print 'Tab delimit is there'
 end
 else
 begin
  print 'Tab delimit is not there'
 end

here the variable @str has string of 'hai how are you' from this find whether the tab delimit is there or not, in above query if condition is checking whether tab delimit is there are not. so if it is tab delimit it will show the message as Tab delimit is ther or else Tab delimit is not there.

Answers (2)