I am still fairly green when it comes to SQL joins. The below code works but I want to check that I am doing it the best way before I copy and paste errors into other work in the future.
The idea of the below code is to get the
Name of a property from the first Table and using the
PropertyID join them. In this case I am actually using every field in Table B (thus the *).
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQL %>" SelectCommand=" select TblA.PropertyID as PId, TblA.Propertyname as PNa, TblB.* from TbPropertyDetails as TblA inner join TbPropertyDetailsSafeguarding as TblB on TblA.PropertyID = TblB.PropertyID where TblA.RegionID <> '0' and TblA.PropertyID LIKE '%' + @PropertyID + '%' order by TblA.PropertyID asc;" > <SelectParameters> <asp:SessionParameter DefaultValue="" Name="PropertyID" SessionField="PropertyID" Type="string" /> </SelectParameters> </asp:SqlDataSource>
I am programming in VB.net but this is really standalone SQL.