0

I have this simple merge statement but it failed when running.
Any advice is appreciated.

MERGE INTO HP.SampleAll as A 
USING ( 
        select ALIGNED
        from HP.Sample2
       ) as B
ON (A.md_nbr = B.md_nbr)
WHEN MATCHED THEN UPDATE
    SET ALIGNED = A.ALIGNED ;
TTPitt
  • 11
  • 1
  • "Failed"? Error message? There's no `B.md_nbr` selcted. – dnoeth Nov 28 '19 at 22:21
  • Please post your exact error message. Also, your `SET ALIGNED = A.ALIGNED` statement doesn't look right. The way you have it now, it doesn't look like you're setting a new value. Do you mean to have `SET A.ALIGNED = B.ALIGNED`? – ravioli Nov 29 '19 at 03:52
  • Missing/Invalid SQL statement'E(3810) – TTPitt Dec 01 '19 at 15:37
  • According to the syntax...that's how you assign values for a merge statement WHEN MATCHED THEN UPDATE SET ALIGNED = A.ALIGNED I have tried several ways but none work so far – TTPitt Dec 01 '19 at 15:38

1 Answers1

0

Error 3810 says that Column does not exist.

md_nbr dont exist in your subquery B - as you don't select it.

Maybe a solution is:

MERGE INTO HP.SampleAll as A 
USING ( 
        select ALIGNED, md_nbr
        from HP.Sample2
       ) as B
ON (A.md_nbr = B.md_nbr)
WHEN MATCHED THEN UPDATE
 SET ALIGNED = A.ALIGNED ;

or just USING HP.Sample2 as B

hhoeck
  • 361
  • 2
  • 3