user23235629
user23235629

Reputation: 21

SYBASE query with parameter in a stored procedure

In a SQL Server stored procedure, I can write like this:

begin
    declare 
    @sSQL       varchar(max),
    @cod1       varchar(10)

    set @sSQL='update myTable set col_name=''ERR'' where col_id=''' + @cod1 + '''';
    exec (@sSQL);
end;

How can I do the same with a Sybase stored procedure? I need to execute a SQL command with variables.

When I try to write the same code in SYBASE, I got a syntax error on exec (@sSQL);

Upvotes: 1

Views: 142

Answers (1)

Emanuel M Barreiros
Emanuel M Barreiros

Reputation: 61

You could try something like this.

SET @sSQL = 'UPDATE myTable SET col_name = ''ERR'' WHERE col_id = ''' + @cod1 + ''''

EXECUTE IMMEDIATE @sSQL

As exec() for this purpose not exist in sybase, you can use EXECUTE IMMEDIATE as a fast solution.

Upvotes: 1

Related Questions