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 2012 Forums
 Transact-SQL (2012)
 How to add so I get productName in the result

Author  Topic 

tojo
Starting Member

5 Posts

Posted - 2014-03-15 : 13:00:49
I have this relation.
Booking with primary key BookingID
Products with primary key ProductID
We have many to many between Booking and Products so we have a connection table BookingDetails in between.
This BookingDetails have primary key BookingID and ProductID

In addition I have a Customers table.
One Customer can have many bookings.

In this select clause I want to add in the result the ProductName that exist in the Products table.
How could I do that ?

Command.CommandText = "SELECT BokningFromDate, BokningToDate, Name, Address,
Phone, ProductID, EnhetsPris " +
"FROM Bokningar " +
"INNER JOIN Customers " +
"ON Bokningar.CustomerID = Customers.CustomerID " +
"INNER JOIN BokningDetails " +
"ON Bokningar.BokningarID = BokningDetails.BokningarID " +
"ORDER BY Name asc";

//Tony

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-15 : 14:53:26
[code]
"SELECT BokningFromDate, BokningToDate, Name, Address, Phone, ProductID, EnhetsPris , ProductName " +
"FROM Bokningar " +
"INNER JOIN Customers " +
"ON Bokningar.CustomerID = Customers.CustomerID " +
"INNER JOIN BokningDetails " +
"ON Bokningar.BokningarID = BokningDetails.BokningarID " +
"INNER JOIN Products " +
"ON BokningDetails.ProductID=Products.ProductID"

[/code]


sabinWeb MCP
Go to Top of Page
   

- Advertisement -