One table Test with single column. These are the values in
the table
a
b
c
d
e
f
g
h
I need a query (without using any variable) with output as -
a b c
d e f
g h



One table Test with single column. These are the values in the table a b c d e f g h I ne..

Answer / gopi muluka

Check this

DECLARE @Character TABLE
(
Ch VARCHAR(50)
)

INSERT INTO @Character
SELECT 'a' UNION
SELECT 'b' UNION
SELECT 'c' UNION
SELECT 'd' UNION
SELECT 'e' UNION
SELECT 'f' UNION
SELECT 'g' UNION
SELECT 'h' UNION
SELECT 'i' UNION
SELECT 'j' UNION
SELECT 'k' UNION
SELECT NULL

SELECT A.Ch,B.Ch,MAX(C.Ch)
FROM @Character A
CROSS JOIN @Character B
CROSS JOIN @Character C
WHERE ASCII(A.Ch)+1=ASCII(B.Ch) AND ASCII(A.Ch)% 3=1
AND ASCII(B.Ch)+1=ISNULL(ASCII(C.Ch),ASCII(B.Ch)+1) AND
ASCII(B.Ch)% 3=2
GROUP BY A.Ch,B.Ch

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What do you understand by physical_only option in dbcc checkdb?

0 Answers  


What is difference between stored procedure & function?

3 Answers   CarrizalSoft Technologies, Concept Infoway, TATA,


What is merge join?

0 Answers  


How global temporary tables are represented and its scope?

0 Answers  


Does the order of columns in update statements matter?

0 Answers  






Insert syudents details in table.Current system date &time insert into joining time.How do insert?( in sysdate only return current system date how do add time?)

0 Answers  


What is RMS migrations?

0 Answers   Satyam,


Tell me the phases a transaction has to undergo?

0 Answers  


How many .ndf files can we create in Sql server 2005?

2 Answers   Wipro,


What is the difference between sql server 2000 object owner and sql server 2005 schema? : sql server database administration

0 Answers  


Please explain the characteristics of a transaction server for example atomicity, consistency, isolation, durability?

0 Answers  


How to check if stored procedure is running in sql server?

0 Answers  


Categories