SQL SERVER INTERVIEW QUESTIONS

1)  How to Select Random Record from TABLE?

 
       SELECT  *  from  < Table Name>  order by  Newid()


2)  Write a query to print 1 to 100 in SQL SERVER without Loop?


;with cte

as
(
select 1[Sequence]
Union All
select [Sequence]+1  from  cte  where  [Sequence]  < 100
)

Select  * from cte


with Loop..


declare @i int;

set @i=0;
while(@i<100)
begin
 select @i=@i+@i
 print @i
end



3) Write a query to Find a number of A in SQL Query?

  SELECT  LEN('VAIKASAA') - LEN(REPLACE('VAIKASAA','A',''))

Ans:4

Comments

Popular posts from this blog

Validate Mobile Number with 10 Digits in ASP.Net