943,753 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1277
  • VB.NET RSS
Sep 5th, 2007
0

Many-to-one relationships

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
nice_true is offline Offline
28 posts
since Sep 2007
Sep 5th, 2007
0

Re: Many-to-one relationships

VB.NET Syntax (Toggle Plain Text)
  1. select
  2. g.Custid,
  3. g.Grno,
  4. g.Name,
  5. case when c.Chno = 123 then c.Chno else null end Chno,
  6. case when c.Chno = 123 then c.Chdate else null end Chdate
  7. from
  8. GrfileB g
  9. join Challan c on g.Grno = c.Grno
  10. where
  11. g.Custid = 1
  12. order by
  13. g.Grno
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 5th, 2007
0

Re: Many-to-one relationships

why do you want to do that? seems strange
Last edited by matale; Sep 5th, 2007 at 1:43 pm. Reason: wa wrong
Reputation Points: 22
Solved Threads: 1
Light Poster
matale is offline Offline
38 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: DataSets in Excel to be used in VB
Next Thread in VB.NET Forum Timeline: Threaded Backup Utility





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC