ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
How can count the string ? 
for ex: If i have string like 'bhaskar' then i need like
b:1
h:1
a:2
s:1
k:1
r:1

please give any idea on that


 Question Submitted By :: Bhaskar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that
Answer
# 1
firstaly take string in any variable. then index with start(')
and end(');then u got the full string length. after that u
substring one character and add (:1) and so on to reach the
last character..

and finally u get result.

bye
 
Is This Answer Correct ?    2 Yes 7 No
Amit Kumar
 
  Re: How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that
Answer
# 2
Private Sub Form_Load()
Dim Str As String
Str = "Bhaskar"
Fetch Str
End Sub

Public Sub Fetch(Str As String)
Dim StrNew As String
StrVal1 = Str: StrNew = Str
While StrNew <> ""
    StrNew = Replace(Str, Mid(Str, 1, 1), "")
    Debug.Print Mid(Str, 1, 1) & Len(Str) - Len(StrNew)
    Str = StrNew
Wend
End Sub
 
Is This Answer Correct ?    1 Yes 4 No
Major
 
 
 
  Re: How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that
Answer
# 3
In SQL Server 2005 New query window for any database.

declare @char as charchar(20)
set @char='bhaskar'

declare @i as int
declare @cnt as int

set @i=1
set @cnt=1

Create table #temp (charval varchar(4) )

while (@i < len(@char) )
begin 
 set @cnt = @cnt + (select count(1) from #temp where 
substring(charval,1,1) = substring(@char,@i,1))

	if (@cnt>1)
	begin
		update #temp set charval = (substring
(@char,@i,1)+':'+ Convert(varchar(20),@cnt) ) where 
substring(charval,1,1) = substring(@char,@i,1)
	end
	else
	begin
		Insert into #temp values (substring
(@char,@i,1)+':'+ Convert(varchar(20),@cnt) )
	end

	print @i
	set @i = @i+1

	set @cnt=1
end

select * from #temp

=======================
You will get result as required.
 
Is This Answer Correct ?    1 Yes 2 No
Santosh Kairamkonda
 
  Re: How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that
Answer
# 4
In SQL Server 2005 New query window for any database.

declare @CharVal varchar(100),@i int
declare @temp table (CharVal varchar(10))

set @a='Bhaskar'

set @i=1
while (@i<=len(@a))
begin

  insert into @temp values (substring(@a,@i,1))

set @i=@i +1

end 

select CharVal, count(*) from @temp group by CharVal
 
Is This Answer Correct ?    5 Yes 1 No
Suni Soni
 
  Re: How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that
Answer
# 5
the good away to count is convert it to a arry and the 
count the array element.. you can do as you like with array.
 
Is This Answer Correct ?    0 Yes 1 No
Debasish
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What is database replicaion? What are the different types of replication you can set up in SQL Server?  2
How to delete an attribute from the emp table  3
PC(code, model, speed, ram, hd, cd, price) Find the hard drive sizes that are equal among two or more PCs. APX2
How to Generate a Series of Random Integers With T-SQL?  1
What is the difference between Stored Procedure , Function and Package, 1. how many blocks in Package and what are they. IBM5
What is the difference Between Sql-server 2000 & 2005 Value-Labs2
What is an extended Stored Procedure?  1
Explain different isolation levels?  3
How do I compare two values when one value(data type) is char and the other is an integer?  3
explain different types of jions with examples briefly? Zensar2
Questions on identity? Infosys1
wat is the main diff between sql server 2000and sql server 2005 Jade-Software6
What are cursors? Name four types of cursors and when each one would be applied? Adea-Solutions1
What is cursor ? And what is difference between Trigger ? HCL1
What is the basic difference between clustered and a non-clustered index?  3
what is mean by crystal repoart? ahere we will mainly use that?  1
Can you give an example of Stored Procedure?  2
How To Change Column Ordinal Position in SQL Server 2005 using Query i.e I Want To Add Column at Particular Ordinal Position in SQL Server 2005  2
How to find the last update record in SQL Server?  3
Delete duplicate rows from a table without primary key by using a single query Table Employee empname salary A 200 B 300 A 200 C 400 D 500 D 500 Output should be A 200 B 300 C 400 D 500  2
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com