Groups | Blog | Home
all groups > sql server programming > december 2004 >

sql server programming : Query Issue


Anith Sen
12/1/2004 5:47:59 PM
Do:

DECLARE @id INT
SET @id = 122 ;
SELECT tbl2.question, tbl2.link, tbl2.url
FROM tbl1
CROSS JOIN ( SELECT 1 UNION
SELECT 2 UNION
SELECT 3 ) D ( n )
INNER JOIN tbl2
ON tbl2.question = CASE n WHEN 1 THEN c1
WHEN 2 THEN c2
WHEN 3 THEN c3
END
WHERE tbl.id = @id ;
ORDER BY n;

--
Anith

William
12/1/2004 11:09:38 PM
Would you kindly take a moment to look at the following:



Table1

Columns: Id email 1 2
3

Data 122 d@d.com 3 1
2

133 a@a.com 2 3
2



Table2 (this table always has the same static data)

Columns: question link url

1 This is a link
www.yahoo.com

2 This is a link
www.google.com

3 This is a link
www.teoma.com



I am looking for a recordset via a "Select" statement that will product the
following (notice the order) for id=122.



Columns: question link url
value

1 This is a link
www.yahoo.com 3

3 This is a link
www.teoma.com 2

2 This is a link
www.google.com 1



And this for id=133.

Columns: question link url
value

2 This is a link
www.google.com 3

1 This is a link
www.yahoo.com 2

3 This is a link
www.teoma.com 2



The important factor is that value has been joined with question, link and
url and that value is in descending order.

AddThis Social Bookmark Button