Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.ms-sqlserver > #1735
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Tony Johansson" <johansson.andersson@telia.com> |
| Newsgroups | comp.databases.ms-sqlserver |
| Subject | Re: How could I add ProductName in this select query |
| Date | Sat, 15 Mar 2014 17:50:01 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 46 |
| Message-ID | <lg20c0$9jp$1@dont-email.me> (permalink) |
| References | <lg1tp6$ldu$1@dont-email.me> <XnsA2F1B216F1D6AYazorman@127.0.0.1> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="Windows-1252"; reply-type=original |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sat, 15 Mar 2014 16:50:09 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="8fdc2b5af81c338deb7045fc6c39b0e2"; logging-data="9849"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZVqwAyLpJMG5n7GU6lKX6" |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.0.6002.18463 |
| In-Reply-To | <XnsA2F1B216F1D6AYazorman@127.0.0.1> |
| X-Newsreader | Microsoft Windows Mail 6.0.6002.18197 |
| Cancel-Lock | sha1:iN4K4eCKeCxsJE7DNz3YZ4BpQv8= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| Xref | csiph.com comp.databases.ms-sqlserver:1735 |
Show key headers only | View raw
Where is the ProductName in the select that you wrote ? //Tony "Erland Sommarskog" <esquel@sommarskog.se> skrev i meddelandet news:XnsA2F1B216F1D6AYazorman@127.0.0.1... > Tony Johansson (johansson.andersson@telia.com) writes: >> The primary key in Products is ProductID In this select clause I want to >> add in the result the ProductName that exist in the Product 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"; >> > > Command.CommandText = > @"SELECT BokningFromDate, BokningToDate, Name, Address, > Phone, ProductID, EnhetsPris, P.ProductID > FROM Bokningar B > JOIN Customers C ON B.CustomerID = C.CustomerID > JOIN BokningDetails BD ON B.BokningarID = BD.BokningarID > JOIN Products P ON BD.ProudctID = P.ProductID > ORDER BY Name asc"; > > Assumining that the language is C#, by using the @ prefix for a string > literal, it can spill over many lines. This increases the readability > of the SQL. I have also introduced aliases for the tables, also to > improve readability. Repeating the table names again and again, makes > it difficult to see the forest for the trees. > > You should have prefixes for all columns in a multi-table query. This > makes the query easier to read for anyone who don't know the tables > by heart. It also prevents the query from breaking if a column with > the same name is added to another table in the query. > > > -- > Erland Sommarskog, Stockholm, esquel@sommarskog.se
Back to comp.databases.ms-sqlserver | Previous | Next — Previous in thread | Next in thread | Find similar
How could I add ProductName in this select query "Tony Johansson" <johansson.andersson@telia.com> - 2014-03-15 17:05 +0100
Re: How could I add ProductName in this select query Erland Sommarskog <esquel@sommarskog.se> - 2014-03-15 17:30 +0100
Re: How could I add ProductName in this select query "Tony Johansson" <johansson.andersson@telia.com> - 2014-03-15 17:50 +0100
Re: How could I add ProductName in this select query "Tony Johansson" <johansson.andersson@telia.com> - 2014-03-15 18:09 +0100
csiph-web