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 are the advanced features in sql 2008?

2 Answers   Wipro,


Hi Can any one tell me the Good institute to learn SQL esp for Data Base Testing or SQL from scratch to the proficiency level in Hyederabad and facult also. Thankyou well in advance

6 Answers  


How to create a view using data from another view?

0 Answers  


What is sql server programming?

0 Answers  


How can u convert the Date to String?

6 Answers   Microsoft, TCS,






what is the disadvantage of SQL Loder?

1 Answers   TCS,


how to create a scrollable cursor with the scroll option? : Sql server database administration

0 Answers  


what is a cursor and what is its use?

2 Answers   L&T,


What is nonclustered index with included columns ?

0 Answers  


What is temporal data type?

0 Answers  


What is built-in/administrator?

0 Answers  


What is truncate table?

0 Answers  


Categories