Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 19th, 2005, 03:14 PM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default help - how to get different values from same table

Dear Friends,
I have 2 tables --> User and Car. Both have unique ids and each user has 2 cars.

for example,
Jim has Ford and Honda
Jill has Toyota and Subara
Jack has Toyota and Honda
John has Ford and Ford

So I am storing the 2 car ids in the user table. I am not creating any bridge table.

So in the report I want the user and their car. But I get the following report on the above data:

Jim -- Ford
Jill -- Toyota
Jack -- Toyota
John -- Ford -- Ford

Notice, that the first 3 records just display first car. The forth record displays both cars.

In the crystal report, I did like this in the "SQL Expression Fields" to get the name of first car:

(SELECT "CAR"."NAME" WHERE "USER."FIRST_CAR_ID" = "CAR"."CAR_ID")


to get the name of second car:

(select "CAR"."NAME" where "USER"."SECOND_CAR_ID" = "CAR"."CAR_ID")


Kindly help me to resolve this problem.
Thanks.


  #2 (permalink)  
Old July 20th, 2005, 04:19 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I assume that both of these tables are small at the moment so could you do a SELECT * from both tables and post the data so I can have a look and try to recreate your example.

Thearon
  #3 (permalink)  
Old July 20th, 2005, 08:25 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Thearon,
Each user has 2 cars and both the car ids are being stored in the user table. The database has been designed and is currently being used so I am not able to change the design and I have to work with this design.

The tables and the data is as follows:

Table: Car
Fields: ID, Name
Data:
1, Ford
2, Honda
3, Toyota
4, Subaru

Table: User
Fields: ID, Name, Car1, Car2
Data:
1, Jim, 1, 2
2, Jill, 3, 2
3, Jack, 3, 2
4, John, 1, 2

The required report is as follows:
User Car1 Car2
---- ---- ----
Jim Ford Honda
Jill Toyota Subaru
Jack Toyota Honda
John Ford Ford

Currently, Crystal is producing the following report:
User Car1 Car2
---- ---- ----
Jim Ford
Jill Toyota
Jack Toyota
John Ford Ford

Hence, if both Car1 and Car2 are same then it is showing else it is not showing.

The back-end is SQL Server 2000 but I do not have direct access to it. And in the crystal report, I did like this in the "SQL Expression Fields"

To get the name of first car:

(SELECT CAR.NAME WHERE USER.CAR1 = CAR.ID)

To get the name of second car:

(Select CAR.NAME where USER.CAR2 = CAR.ID)

But if I Browse the data by right-clicking, it shows me the correct result for both the fields - Car1 name and Car2 name, but it does not show on the report.

Thanks for reply and I appreciate your help. If you need more information, please let me know.
Thanks.

  #4 (permalink)  
Old July 21st, 2005, 04:22 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

OK, not being a crystal expert or even that familiar with crystal I'm not sure how to tell you to do this. But, the following query will produce the results you desire. So your task will be to get crystal to this query.

BTW, I named my tables Users and Cars.

Thearon

SELECT Users.Name AS [User], Car1.Name AS Car1, Car2.Name AS Car2
FROM Users
JOIN Cars AS Car1 ON Users.Car1 = Car1.ID
JOIN Cars AS Car2 ON Users.Car2 = Car2.ID
ORDER BY [User]
  #5 (permalink)  
Old July 22nd, 2005, 12:39 PM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Thearon,
Thanks for code, it works great and it produces the required results and geneates the report as designed.
Thanks again.:)

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Two values from same table MArgente BOOK: Beginning SQL 3 December 11th, 2009 07:35 AM
Comparinng Two Values from same table MArgente Access 1 June 12th, 2007 04:06 PM
accessing table values in VB pettrer ASP.NET 2.0 Basics 1 April 22nd, 2006 09:58 AM
searching a table for values Nayt32 Access VBA 4 February 27th, 2006 11:19 AM
Adding 2 values in a table Regornil JSP Basics 2 September 13th, 2004 02:32 AM



All times are GMT -4. The time now is 10:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.