Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have a very basic UPDATE SQL -

UPDATE HOLD_TABLE Q SET Q.TITLE = 'TEST' WHERE Q.ID = 101;

This query runs fine in Oracle, Derby, MySQL - but it fails in SQL server 2008 with following error:

"Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'Q'."

If I remove all occurrences of the alias, "Q" from SQL then it works.

But I need to use the alias.

1 Answer

0 votes
by (40.7k points)

You can use the syntax for using an alias in an update statement on SQL Server like this:

UPDATE Q

SET Q.TITLE = 'TEST'

FROM HOLD_TABLE Q

WHERE Q.ID = 101;

Note: Although, using the alias is not mandatory here.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 8, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 19, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...