Alex Rivera | Logout

What is the difference between CALL and EXEC in T-SQL?

Asked 2011-10-21T07:42:41.193
21

Consider:

CREATE PROCEDURE LowerCityDiscounts @city VARCHAR(45), @decrease DECIMAL(10,2) AS
BEGIN
    BEGIN TRANSACTION;
    UPDATE Customers SET discnt = discnt - @decrease
    WHERE Customers.city = @city;

    UPDATE Customers SET discnt = 0
    WHERE Customers.city = @city AND discnt < 0
    COMMIT;
END;

I tried to call this procedure with:

CALL LowerCityDiscounts 'Cleveland', 5;

but this only produces

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

Yet, if I change things to

EXEC LowerCityDiscounts 'Cleveland', 5;

everything works fine. This despite that the documentation stating that call is the right syntax.

Why does EXEC work when CALL does not?

Edit
Report

1 Answer

20

Yup.. CALL is an construct/syntax usable from an ODBC driver, as your documentation indicates.

There's no reference in the T-SQL documentation to CALL, only EXEC.

It doesn't work because it's not T-SQL.

answered 2011-10-21T07:46:51.017

Your Answer