Skip to content
Advertisement

how to insert two select in a select command of a sqldatasource

I have to insert two select in a select command of a sqldatasource that is linked to a dropdownlist but I don’t know how to do it.

I tried it but it doesn’t work:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnection %>" 
SelectCommand="SELECT [ID], [RagioneSociale] FROM [Persona] 
WHERE Tipocliente = 2 AND SELECT [ID_Società] FROM [Persona] 
WHERE ID_Società IS NOT NULL"></asp:SqlDataSource>
|ID    RagioneSociale    Piva              tipocliente  ID_Società|
|56    Amazon           33232432423         2           NULL      |
|80    plutooo           1231234            2            56       |

Advertisement

Answer

It sounds like you just need to do one SELECT statement but with two conditions. You can do it like this:

SelectCommand="SELECT [ID], [RagioneSociale], [ID_Società] FROM [Persona] 
               WHERE Tipocliente = 2 AND ID_Società IS NOT NULL"

If you really want to do the two seperate queries then you’ll have the UNION the table together or do two separate subqueries then JOIN them. However this will most likely result in a lot of duplicates.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement