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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

how to define testing of network layers? : Sql server database administration

657


What is the difference function and stored procedure?

720


You want to check the syntax of a complicated update sql statement without executing it. What command should you use?

677


What is tempdb database? : SQL Server Architecture

787


What is PROJECTION Operation?

767






How to count duplicated values in a column in ms sql server?

700


Is it safe to delete log files?

675


What is difference between rownum and rowid?

669


What are the different types of sub-queries?

765


What does the on delete cascade option do?

747


How to use order by with union operators in ms sql server?

755


What is difference between equi join and inner join?

652


What are the operating modes in which database mirroring runs?

816


What is the dbcc command and why is it used?

760


What is the difference between web edition and business edition?

103