October 10, 2011 at 4:17 am
I have 2 tables, say ,tab1 and tab2 having the same fields-id and modifier that can be related by ID.
TAB Aidmodifier
1a
b
c
d
e
2a
and
TAB Bid modifier
1a
b
2a
b
c
Now, i want to display the result as shown below:-
idmodifierAmodifierB
1aa
bb
c
d
e
2aa
b
c
How could i achieve this ? Plz help me out....
October 12, 2011 at 2:25 am
You didn't give much detail of your issue, but I guess this should do the trick.
DECLARE @a TABLE (
id int,
modifier char(1)
)
INSERT INTO @a VALUES (1, 'a')
INSERT INTO @a VALUES (1, 'b')
INSERT INTO @a VALUES (1, 'c')
INSERT INTO @a VALUES (1, 'd')
INSERT INTO @a VALUES (1, 'e')
INSERT INTO @a VALUES (2, 'a')
DECLARE @b-2 TABLE (
id int,
modifier char(1)
)
INSERT INTO @b-2 VALUES (1, 'a')
INSERT INTO @b-2 VALUES (1, 'b')
INSERT INTO @b-2 VALUES (2, 'a')
INSERT INTO @b-2 VALUES (2, 'b')
INSERT INTO @b-2 VALUES (2, 'c')
SELECT ISNULL(A.id, B.id) AS id,
A.modifier AS modifierA,
B.modifier AS modifierB
FROM @a AS A
FULL JOIN @b-2 AS B
ON A.ID = B.ID
AND A.modifier = B.modifier
Hope this helps
Gianluca
-- Gianluca Sartori
October 12, 2011 at 9:15 pm
select 1 as tblid,column1,column2 from table1
union all
select 2 as tblid,column1,column2 from table2
order by 1,2,3
October 12, 2011 at 11:44 pm
Thank you,Very much.....Sartori...
October 13, 2011 at 1:29 am
You're welcome, glad I could help.
-- Gianluca Sartori
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply