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 is row_number () and partition by in sql server?

1 Answers  


How to insert data into an existing table?

1 Answers  


how can you attach more than 20 ldf files in sql server

1 Answers   IBM,


How exceptions can be handled in sql server programming?

1 Answers  


Does sql server 2000 full-text search support clustering?

1 Answers  


can you any body tell me the how to decrease the logfile

4 Answers  


Define DML and DCL statements?

1 Answers   Hexaware, NIIT,


i use few third party softwares. they r all having their own databases . but the data is repeated in all these databases - say a person is in all the three databases, but his name is stoared in diff format in all databases i want to create a centralised database ,and i dont want to re-enter the records . using the exisating records how can i build a centralised database?

1 Answers   Fidelity,


Do you know what are the reporting services components?

1 Answers  


Mention the differences between sql server and mysql.

1 Answers  


What are the parts of a function?

1 Answers  


How can we check the sql server version?

1 Answers  


Categories