I am trying to find out is there a way to take the string data in the Name, Address, and DSL columns that has been concatenated in STUFF() and XML PATH and display it vertically in same row instead of horizontally on the front end. I am using a gridview to display the information.
SELECT i.[InstrumentID], it.[InstrumentType],i.[InstrumentNumber], i.[NANumber],i.[DateTimeFiled],
STUFF((SELECT ', ' + n.[Surname] + n.[GivenName] + '(' + nc.[NameCode] + ')' FROM [dbo].[tblName] n
INNER JOIN [dbo].[tblNameCode] nc ON nc.[NameCodeID] = n.[NameCodeID] Where n.[InstrumentID] = i.[InstrumentID] ORDER BY n.[Surname] FOR XML PATH (''), TYPE).value('.', 'varchar(max)'), 1, 1, '') AS Name ,
STUFF(( SELECT ',' + a.[StreetNumber] + a.[StreetName] FROM [dbo].[tblAddress] a Where a.[InstrumentID] = i.[InstrumentID] ORDER BY a.[StreetName] FOR XML PATH (''), TYPE).value('.', 'varchar(max)'), 1, 1, '') AS Address,
STUFF(( SELECT '' + d.[District] + ' ' +d.[Square]+ ' ' + d.[Lot] + ', ' FROM [dbo].[tblDLS] d WHERE d.[InstrumentID] = i.[InstrumentID] FOR XML PATH (''), TYPE).value('.', 'varchar(max)'), 1, 1,'') AS DSL
FROM [dbo].[tblInstrument] i
INNER JOIN [dbo].[tblInstrumentType] it ON i.[InstrumentTypeID] = it.[InstrumentTypeID]
WHERE InstrumentNumber = 1
ORDER BY InstrumentNumber, InstrumentType
Here is my output
There is nothing wrong as far as getting results. The issue is getting the data Vertical. Here is a screenshot of my program also:
Here is the aspx code for displaying the info:
<Columns>
<asp:TemplateField HeaderText="Instrument #, Type, Dist., Squ. , Lot">
<ItemTemplate>
<asp:LinkButton ID="LbPath" runat="server"
Text='<%# String.Format("{0} {1}", Eval("InstrumentNumber"), Eval("InstrumentType")) %>'
CommandName="GetInstrument"
CommandArgument='<%#Bind("instrumentID") %>'>
</asp:LinkButton>
<br />
<asp:Label ID="lblDateFiled" runat="server" Text='<%# Eval("DateTimeFiled") %>'> </asp:Label>
<br />
<asp:Label ID="lblNANumber" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text="NA Number: " ForeColor="#434343"></asp:Label><%# Eval("NANumber") %>
<br />
<br />
<asp:Label ID="lblDSL" runat="server" Text='<%#Eval("DSL") %>'> </asp:Label>
<%--<asp:Label ID="lblDSL" runat="server" Text='<%# String.Format("{0} {1} {2}", Eval("District"), Eval("Square"), Eval("Lot")) %>'> </asp:Label> --%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name, Address" SortExpression="Surname">
<ItemTemplate>
<EditItemTemplate>
<%-- <asp:Label ID="label1" runat="server" Text='<%# Bind("instrumentID") %>' ></asp:Label>--%>
</EditItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
<%-- <asp:Label ID="lblName" runat="server" Text='<%# String.Format(" {0}, {1} ({2})", Eval("Surname"), Eval("GivenName"), Eval("Namecode")) %>'></asp:Label>--%>
<br />
<asp:Label ID="lblAddress" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text='<%# Eval("Address") %>'></asp:Label>
<%--<asp:Label ID="lblAddress" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text='<%# String.Format("{0} {1} {2}", Eval("Subdivision"), Eval("StreetNumber"), Eval("StreetName")) %>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="InstrumentType" HeaderText="Instrument Type" InsertVisible="false" ReadOnly="true" SortExpression="InstrumentType" />
<asp:BoundField DataField="NANumber" HeaderText="NANumber" InsertVisible="false" SortExpression="NANumber" />
<asp:BoundField DataField="DateTimeFiled" HeaderText="DateTimeFiled" InsertVisible="false" ReadOnly="true" SortExpression="DateTimeFiled" />--%>
</Columns>
Assuming I understand your need, you could try something like the following:
Returns