Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 inner join problem.....

Author  Topic 

hemant_ec48
Starting Member

7 Posts

Posted - 2009-11-30 : 07:40:00
while inner join two table how to get blank value in master data.

Let me say....

M1----Q1
""----Q2


Like this...If i inner join M & Q table....I am facing this problem .

Requirement is that if I inner join it gives me

M1---Q1
M1---Q2

but i want it should come only once like above..while second time it should come blank.


Hemant Patel
Contact me : 09726242864

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 07:43:15
I have given the answer here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=136500

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-11-30 : 07:45:23
quote:
Originally posted by madhivanan

I have given the answer here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=136500

Madhivanan

Failing to plan is Planning to fail



So did I

PBUH
Go to Top of Page

hemant_ec48
Starting Member

7 Posts

Posted - 2009-11-30 : 07:46:05
Sorry my friend that in not a answer...on that post i have ask some what complecated Question...so i have post new one....with easy way....


thanks,

Hemant Patel
Contact me : 09726242864
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 07:49:58
quote:
Originally posted by hemant_ec48

Sorry my friend that in not a answer...on that post i have ask some what complecated Question...so i have post new one....with easy way....


thanks,

Hemant Patel
Contact me : 09726242864


Have you seen that thread again?
You have new answers there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-11-30 : 07:51:10
Instead of keeping us going in circles please post some sample data & expected outptut.
Please follow this link http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx for more information on how to do so.

PBUH
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-30 : 08:00:07
It's bad...I know

-- generate some test data
declare @M table (Mid int)
declare @Q table (Qid int, Mid int, QValue varchar(255))

insert @M
select 1 union all
select 2

insert @Q
select 10,1,'Q10 value' union all
select 11,1,'Q11 value' union all
select 12,1,'Q12 value' union all
select 20,2,'Q20 value' union all
select 21,2,'Q21 value'

-- classic inner join resultset...
select
convert(varchar(255),m.Mid) as Mid,
q.QValue
from @M as m
inner join @Q as q on m.Mid = q.Mid
order by m.Mid,q.Qid

-- resultset without repeating Master data
select
case
when rownum=1 then Mid else '' end as newMid,
QValue
from
(select
row_number() over (partition by m.Mid order by m.Mid) as rownum,
convert(varchar(255),m.Mid) as Mid,
q.QValue,
q.Qid
from @M as m
inner join @Q as q on m.Mid = q.Mid)dt
order by Mid,Qid



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -