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 create statement?

0 Answers  


can we give the identity for existing column of the table? (already table contains 10(1-10) unique randam records)

2 Answers  


What is multi-statement table-value user-defined function?

0 Answers  


What is store procedure? When do you use?

0 Answers  


How can you control the amount of free space in your index pages?

0 Answers  






what are the limitations of parameters in a storedprocedure

1 Answers  


I have Two table First have UserName and second is address, in address table more than value relegated to UserName table, i want to fetch 2nd address if exist other wise 1st address access

4 Answers  


Explain the third normal form(3nf)?

0 Answers  


What guidelines should be followed to help minimize deadlocks?

0 Answers  


Why truncate is ddl?

0 Answers  


How will you go about resolving deadlocks?

0 Answers  


What are the advantages of policy management?

0 Answers  


Categories