0

我正在尝试内部连接asp_Usersasp_Membership表,以便我可以从我拥有的a中检索该CreateDate字段。asp_MembershipBoundFieldGridView

我尝试了以下对我来说似乎有意义的方法,但它不断抛出错误:

A field or property with the name 'CreateDate' was not found on the selected data source.

 ALTER PROCEDURE [dbo].[stp_Customer_Fetch_Paged]
    (
        @sortExpression nvarchar(100),
        @startRowIndex int,
        @maximumRows int
    )
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;

        -- Make sure a @sortExpression is specified
        IF LEN(@sortExpression) = 0 
            SET @sortExpression = 'aspnet_Users.UserId'

        -- Issue query
        DECLARE @sql nvarchar(4000)
        SET @sql = '
        SELECT userid, username, first_name, last_name, town,postcode, rowrank FROM (
    SELECT     aspnet_Users.UserId, aspnet_Membership.UserId as MembershipID, aspnet_Membership.CreateDate, aspnet_Users.UserName, Customer.title, Customer.first_name, Customer.last_name, Customer.telephone, 
                          Customer.dpa_consent, Customer.billing_address_id, Address.friendly_name, Address.address_line_1, Address.address_line_2, 
                          Address.address_line_3, Address.town, Address.postcode, ROW_NUMBER() OVER (ORDER BY ' + @sortExpression + ' ) AS RowRank
    FROM  Customer INNER JOIN
                          aspnet_Users ON Customer.userid = aspnet_Users.UserId 
                          INNER JOIN
                          Address ON Customer.billing_address_id = Address.address_id AND Customer.userid = Address.user_id
                          INNER JOIN
                          aspnet_Membership ON
                          aspnet_Membership.UserId = aspnet_Users.UserId

        ) AS ProductsWithRowNumbers
        WHERE RowRank > ' + CONVERT(nvarchar(10), @startRowIndex) + 
        ' AND RowRank <= (' + CONVERT(nvarchar(10), @startRowIndex)+ ' +  ' +
        CONVERT(nvarchar(10), @maximumRows) + ')'

        print @sql

        -- Execute the SQL query
        EXEC sp_executesql @sql

    END

尽管我在存储过程中选择了它。我对 SQL 很陌生,所以它可能是我忽略的一些简单的东西?任何帮助是极大的赞赏。

谢谢你。

4

1 回答 1

2

您的最外层SELECT子句不包括该列:

SELECT userid, username, first_name, last_name, town,postcode, rowrank

需要是

SELECT userid, username, first_name, last_name, town,postcode, CreateDate, rowrank
于 2012-06-01T15:30:20.080 回答