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
What is 1nf normalization form?
What is the difference between functions and stored procedures?
Mention the differences between having and where clause.
What is the difference between a stored procedure and a user defined function?
How to stop a loop early with break statements in ms sql server?
What program is used to store the data source file?
Why are sql functions used?
What are the steps you should follow to start sql server in single-user mode?
what is normalization? Explain different levels of normalization? : Sql server database administration
Explain features of analysis services?
How does recursive cte works in sql server?
What are audit control procedures?
what are the types of indexes? : Sql server database administration
You want to implement the one-to-one relationship while designing tables. How would you do it?
How many types of stored procedures are there in sql server?