Hi all,
I am doing the change from having worked in Oracle for a long time to
MS SQL server and am frustrated with a couple of simple SQL stmt's. Or
at least they have always been easy.
The SQL is pretty straightforward . I am updating a field with a Max
effective dated row criteria. (PepopleSoft app)
update PS_JOB as A set BAS_GROUP_ID = ' '
where EMPL_STATUS in ('D', 'L', 'R', 'S', 'T')
and EFFDT = (select max(EFFDT) from PS_JOB where EMPLID = A.EMPLID)
This stmt is not working. I am getting an error on the keyword 'as'. I
have tried:
update PS_JOB A set...
update PS_JOB from PS_JOB A set...
Same result, error on 'A' or error on 'from'.
I also tried to add the table alias to the sub query, which
technically worked, but with wrong data result.
So my question comes down to: How do I use a table alias in an update
statement in MS SQL server?
I worked around this by creating a temp table. But that does not
fulfill my curiosity, nor is it an ideal solution.
Thanks a lot,
-OK
I am doing the change from having worked in Oracle for a long time to
MS SQL server and am frustrated with a couple of simple SQL stmt's. Or
at least they have always been easy.
The SQL is pretty straightforward . I am updating a field with a Max
effective dated row criteria. (PepopleSoft app)
update PS_JOB as A set BAS_GROUP_ID = ' '
where EMPL_STATUS in ('D', 'L', 'R', 'S', 'T')
and EFFDT = (select max(EFFDT) from PS_JOB where EMPLID = A.EMPLID)
This stmt is not working. I am getting an error on the keyword 'as'. I
have tried:
update PS_JOB A set...
update PS_JOB from PS_JOB A set...
Same result, error on 'A' or error on 'from'.
I also tried to add the table alias to the sub query, which
technically worked, but with wrong data result.
So my question comes down to: How do I use a table alias in an update
statement in MS SQL server?
I worked around this by creating a temp table. But that does not
fulfill my curiosity, nor is it an ideal solution.
Thanks a lot,
-OK
Comment