Self Join error

Self Join error

am 07.11.2007 20:40:53 von Tangz

Hi all,

I am trying to do a simple insert into query that inserts data from
one table to itself. Here is the design of my table:

Batch_Desc - Primary Key
Item_Total
Desc
Subtotal

What i am trying to do is strip a few characters from Batch_Desc using
Left(Batch_Desc, 12) and append that to Desc column. Here is my query:

INSERT INTO Works_Batch ( [Desc] )
SELECT Left([a].[Batch_Desc],12) AS [Desc]
FROM Works_Batch INNER JOIN Works_Batch AS a ON Works_Batch.Batch_Desc
= a.Batch_Desc;

When i run this query i receive an error stating that records cannot
be append due to key violations. As far as i can tell the query looks
fine to be. Does anyone have any idea why there is a problem with this
self join?

Thanks
Thangam

Re: Self Join error

am 07.11.2007 22:23:33 von Salad

Tangz wrote:
> Hi all,
>
> I am trying to do a simple insert into query that inserts data from
> one table to itself. Here is the design of my table:
>
> Batch_Desc - Primary Key
> Item_Total
> Desc
> Subtotal
>
> What i am trying to do is strip a few characters from Batch_Desc using
> Left(Batch_Desc, 12) and append that to Desc column. Here is my query:
>
> INSERT INTO Works_Batch ( [Desc] )
> SELECT Left([a].[Batch_Desc],12) AS [Desc]
> FROM Works_Batch INNER JOIN Works_Batch AS a ON Works_Batch.Batch_Desc
> = a.Batch_Desc;
>
> When i run this query i receive an error stating that records cannot
> be append due to key violations. As far as i can tell the query looks
> fine to be. Does anyone have any idea why there is a problem with this
> self join?
>
> Thanks
> Thangam
>

Do you permit duplicates? Look at your table desing for Works_Batch and
remove the Unique index