Share via

A syntax error - that magically is forgiven my most - but not all - of the SQL Servers - sp_executesq

DANNY ABRAHAM 96 Reputation points
2021-05-21T11:55:58.693+00:00

declare @MSG varchar(200);
declare @stmt nvarchar(2048);
declare @rc integer;
declare @table_name varchar(248)
set @table_name='sys.columns'
set @stmt = N'select @rc=count(*) from '+ @table_name
exec sp_executesql @stmt , N'@rc int output', @rc=@RC OUTPUT
set @MSG ='Records in table ' + @table_name + ' :' + cast(@rc as varchar) ;
select @MSG ;

The syntax is that =@RC is not required, but not always flagged as an error

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.


Answer accepted by question author

DANNY ABRAHAM 96 Reputation points
2021-05-21T13:34:02.983+00:00

Well, Thanks.
The solution is .. The code above will fail when the Instance is case sensitive.
It runs OK when the instance is case insensitive.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.