The column ‘LOCK_ID’ was specified multiple times for ‘BB’.

SQL Server 2008

Error Message: The column ‘LOCK_ID’ was specified multiple times for ‘BB’.

Example:

select BB.LDC_ACCT_ID from
(
select * from STUDENTS S
JOIN RECORDS R
on S.STUDENT_ID = R.STUDENT_ID
) as TEMP

If you run this query in SQL SERVEr 2008, you will get the above error.

Reason

The problem is

select * from <– this line

What is happening is (possibly), both students table and records table have the same field name. When you use * to put two fields with the same name in one table, you get this error. Note that the subquery runs fine by itself. But when you put it inside TEMP table, it causes the error.

Cure

select S.STUDENT_ID, …. from <– this line

This way not duplicate fields are inserted in the TEMP table.

Advertisements
This entry was posted in SQL Server 2008. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s