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

How to use old values to define new values in update statements in ms sql server?

0 Answers  


How to drop an existing stored procedure in ms sql server?

0 Answers  


Which sql server table is used to hold the stored procedure script?

0 Answers  


What is usually the first word in a sql query?

0 Answers  


What are the differences between sql server and mysql.

0 Answers  






Please illustrate physical database architecture? : SQL Server Architecture

0 Answers  


What function does a database engine serve in the sql server?

0 Answers  


What is log shipping?

0 Answers  


sql server has its default date format in da form "yy-mm-dd" its possible to convert da current date format of sql server to desired format. Now my question is dat how to get da previous and comin days date in my desired format??

2 Answers  


How to write a query with an inner join in ms sql server?

0 Answers  


Explain what is log shipping?

0 Answers  


What is BCP? When does it used in sql server 2012?

0 Answers   TryTechnicals Pvt Ltd,


Categories