locked
Select Statment not Working RRS feed

  • Question

  • User1372787940 posted

    The below code will not work i am getting an syntax error near As Fullname

    <asp:SqlDataSource ID="SQLEMPLOYEEHARDWARE" runat="server" ConnectionString="<%$ ConnectionStrings:Inventory %>"
            ProviderName="<%$ ConnectionStrings:Inventory.ProviderName %>"
            SelectCommand="SELECT * FROM [EMPLOYEEHARDWARE] WHERE ([OwnerFirst + OwnerLast] as FULLNAME)">
            <SelectParameters>
                <asp:SessionParameter Name="FULLNAME" SessionField="EMPLOYEENAME" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

    Wednesday, January 6, 2016 4:03 PM

Answers

  • User475983607 posted

    Then the WHERE should contain the following.  Don't forget the space!

    OwnerFirst + ' ' +  OwnerLast = FULLNAME

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 6, 2016 4:19 PM

All replies

  • User475983607 posted

    The syntax is incorrect.  The WHERE clause is like an "if" which evaluates to True or False.  I suspect you are trying filter by concatenating the first and last name and checking if it equals a @FullName parameter

    OwnerFirst + OwnerLast = @FULLNAME

    If you are trying to return the First and last name as a column then you need to move the concatenation to the SELECT 

    [OwnerFirst] + [OwnerLast] as FULLNAME

    Wednesday, January 6, 2016 4:10 PM
  • User1372787940 posted

    I am trying to load a gridview based on a name from the previous page such as Joe Smith

    Wednesday, January 6, 2016 4:13 PM
  • User475983607 posted

    Then the WHERE should contain the following.  Don't forget the space!

    OwnerFirst + ' ' +  OwnerLast = FULLNAME

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 6, 2016 4:19 PM