RSS Forums RSS

Many-to-one relationships

Please support our VB.NET advertiser: DiscountASP.NET – 3 Months Free on VB.NET Web Hosting
Reply
Posts: 26
Reputation: nice_true is an unknown quantity at this point 
Solved Threads: 0
nice_true nice_true is offline Offline
Light Poster

Many-to-one relationships

  #1  
Sep 5th, 2007
Hi!
I am trying to write a procedure which extracts data from 2 tables named partymst and challan.

Fields in Grfile
1) Grno
2) Name

Fields in Challan
1)Grno
2)Chno
3)Chdate


[b][u]Data in GrfileB]

CustID Grno Name
1 123 a
1 345 b
1 456 c
2 123 d
3 123 e
4 123 f




Data in Challan

Grno Chno Chdate
123 0001 01/01/2000
345 0002 01/01/2000
456 0003 01/01/2000
789 0004 01/01/2000
173 0005 01/01/2000
333 0006 01/01/2000



I want the records for custid=1

I have created a join on grno fields from both the tables.

Now, for the records which have Grno=123 in Grfile and Challan,one record will be fetched.

But in case,of the rest 2 records in Grfile which also have Grno=123, I want the fields from the Challan table to remain blank.

How do I write the procedure.

Th o/p I want is

Custid Grno Name Chno Chdate
1 123 a 0001 01/01/2000
1 345 b NULL NULL
1 456 c NULL NULL
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,171
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 64
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Many-to-one relationships

  #2  
Sep 5th, 2007
select 
    g.Custid, 
    g.Grno, 
    g.Name, 
    case when c.Chno = 123 then c.Chno else null end Chno, 
    case when c.Chno = 123 then c.Chdate else null end Chdate 
from 
    GrfileB g 
    join Challan c on g.Grno = c.Grno
where 
    g.Custid = 1 
order by 
    g.Grno
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Posts: 37
Reputation: matale is an unknown quantity at this point 
Solved Threads: 1
matale matale is offline Offline
Light Poster

Re: Many-to-one relationships

  #3  
Sep 5th, 2007
why do you want to do that? seems strange
Last edited by matale : Sep 5th, 2007 at 12:43 pm. Reason: wa wrong
My current Project www.footystat.com
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 931 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:48 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC