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 connect ms access to sql servers through odbc?

555


What is the maximum number of index per table?

568


Can two tables share a primary key?

523


What is report server project?

106


How do I view views in sql server?

522






What do you do in data exploration

568


What do you understand by the data quality services in sql server?

506


How self join is different from outer join?

605


What is difference between getdate and sysdatetime in sql server 2008?

604


Give main differences between "Truncate" and "Delete".

583


How to read data in a table with "select" statements?

565


What is the difference between count () and rowcount ()?

526


What is the parse query button used for?

608


What are subqueries in sql server?

601


How to check if a table is being used in sql server?

519