I noticed you did not assign @ErrStatus after the first select
and you dont set @RowsAffected to anything
not that I think this is your issue
Main Topics
Browse All TopicsHi,
Can someone help me as to why the following SQL is cause the error:
"The multi-part identifier "..." could not be bound."
Thanks.
--------------------------
--region [dbo].[SelectPagedAccounts
--------------------------
-- Procedure Name: [dbo].[SelectPagedAccounts
-- Date Generated: Tuesday, 20 February 2007
-- Author: Stephen McCormack - stephenm@mwebsolutions.com
-- Company: MWeb Solutions Pty Ltd
-- Software: CodeSmith v4.0.0.0
-- Template: StoredProcedures.cst
-- Comments: 'Custom Paging in ASP.NET 2.0 with SQL Server 2005' - http://aspnet.4guysfromrol
--------- --------------------------
CREATE PROCEDURE [dbo].[SelectPagedAccounts
-- paging parameters
@PageNumber int = 1 ,
@PageSize int = 10 ,
-- index column(s)
@AccountID int,
-- sort expressions
@SortBy varchar(50) = 'CreatedDate' ,
@SortDirection varchar(4) = 'DESC'
AS
-- turn off rows affected
SET NOCOUNT ON
--isolation level
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
-- system function stores
DECLARE
@ErrStatus int, -- stores error status
@RowsAffected int -- stores number of rows affected
-- parameter validation
IF (@PageNumber < 1) SET @PageNumber = 1
IF (@PageSize < 1) SET @PageSize = 10
--------------------------
-- Determine start and end row index.
--------------------------
DECLARE
@StartRowIndex int, -- the starting row index
@EndRowIndex int -- the ending row index
SET @StartRowIndex = (@PageNumber-1) * @PageSize
SET @EndRowIndex = (@StartRowIndex + @PageSize)-1
--------------------------
-- Select Paged Set
--------------------------
SELECT
[RowNum],
[dbo].[Accounts].[AccountI
[dbo].[Accounts].[Customer
[dbo].[Customers].[Name] AS [CustomerName], /* fk name column */
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Notes],
[dbo].[Accounts].[CreatedD
[dbo].[Accounts].[CreatedB
[dbo].[Accounts].[Modified
[dbo].[Accounts].[Modified
FROM
(
SELECT
[dbo].[Accounts].[AccountI
[dbo].[Accounts].[Customer
[dbo].[Customers].[Name] AS [CustomerName], /* fk name column */
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Notes],
[dbo].[Accounts].[CreatedD
[dbo].[Accounts].[CreatedB
[dbo].[Accounts].[Modified
[dbo].[Accounts].[Modified
,
ROW_NUMBER() OVER
(
ORDER BY
[dbo].[Accounts].[CreatedD
) AS [RowNum]
FROM
[dbo].[Accounts]
INNER JOIN [dbo].[Customers] ON [dbo].[Accounts].[Customer
WHERE
[dbo].[Accounts].[AccountI
) AS [PagedSet]
WHERE
[RowNum] BETWEEN @StartRowIndex AND @EndRowIndex
-- check for errors
IF @ErrStatus <> 0
BEGIN
RAISERROR( 'Error occurred in stored procedure ''[dbo].[SelectPagedAccoun
RETURN @ErrStatus
END
-- ensure correct number of rows affected
IF @RowsAffected > @PageSize
BEGIN
RAISERROR( 'Unexpected number of rows affected by stored procedure ''[dbo].[SelectPagedAccoun
RETURN -999 -- standardised return code for this - 'Unexpected rowcount'
END
--------------------------
-- RecordCount Resultset
--------------------------
SELECT
COUNT(*) AS [RecordCount]
FROM
[dbo].[Accounts]
/* must use single statement immediately to store system functions
as all DML statements, SELECT, IF, PRINT and SET will reset @@error to zero */
SELECT
@ErrStatus = @@ERROR
-- check for errors
IF @ErrStatus <> 0
BEGIN
RAISERROR( 'Error occurred in stored procedure ''[dbo].[SelectPagedAccoun
RETURN @ErrStatus
END
-- turn on rows affected
SET NOCOUNT OFF
-- success(0)
RETURN 0
--endregion
GO
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
if customer is 1:1 with accounts consider..
SELECT
[RowNum],
[AccountID], /* pk */
[CustomerID], /* fk */
( select C.[Name] from [dbo].[Customers] as C
where pageset.[CustomerID] = C.[CustomerID]
) AS [CustomerName]
[DiscountAmount],
[DiscountRate],
[DiscountCode],
[Notes],
[CreatedDate],
[CreatedBy],
[ModifiedDate],
[ModifiedBy]
FROM
(
SELECT
[dbo].[Accounts].[AccountI
[dbo].[Accounts].[Customer
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Notes],
[dbo].[Accounts].[CreatedD
[dbo].[Accounts].[CreatedB
[dbo].[Accounts].[Modified
[dbo].[Accounts].[Modified
,
ROW_NUMBER() OVER
(
ORDER BY
[dbo].[Accounts].[CreatedD
) AS [RowNum]
FROM
[dbo].[Accounts]
WHERE
[dbo].[Accounts].[AccountI
) AS [PagedSet]
WHERE
[RowNum] BETWEEN @StartRowIndex AND @EndRowIndex
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2007-02-19 at 21:55:36ID: 18568620
SELECT D], /* pk */ ID], /* fk */ Amount], Rate], Code], ate], y], Date], By] ate] DESC ID] = [dbo].[Customers].[Custome rID] D] = @AccountID
[RowNum],
[AccountID], /* pk */
[CustomerID], /* fk */
[Name] AS [CustomerName], /* fk name column */
[DiscountAmount],
[DiscountRate],
[DiscountCode],
[Notes],
[CreatedDate],
[CreatedBy],
[ModifiedDate],
[ModifiedBy]
FROM
(
SELECT
[dbo].[Accounts].[AccountI
[dbo].[Accounts].[Customer
[dbo].[Customers].[Name] AS [CustomerName], /* fk name column */
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Discount
[dbo].[Accounts].[Notes],
[dbo].[Accounts].[CreatedD
[dbo].[Accounts].[CreatedB
[dbo].[Accounts].[Modified
[dbo].[Accounts].[Modified
,
ROW_NUMBER() OVER
(
ORDER BY
[dbo].[Accounts].[CreatedD
) AS [RowNum]
FROM
[dbo].[Accounts]
INNER JOIN [dbo].[Customers] ON [dbo].[Accounts].[Customer
WHERE
[dbo].[Accounts].[AccountI
) AS [PagedSet]
WHERE
[RowNum] BETWEEN @StartRowIndex AND @EndRowIndex