question

DANNYABRAHAM-3831 avatar image
0 Votes"
DANNYABRAHAM-3831 asked DANNYABRAHAM-3831 commented

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

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

sql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I don't understand your question. Parameters may be passed by either name or position so exec sp_executesql @stmt , N'@rc int output', @rc=@RC OUTPUT and exec sp_executesql @stmt , N'@rc int output', @RC OUTPUT are valid.

0 Votes 0 ·

1 Answer

DANNYABRAHAM-3831 avatar image
0 Votes"
DANNYABRAHAM-3831 answered DANNYABRAHAM-3831 commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


How did you make it case-insensitive to run OK?

0 Votes 0 ·

I have built two servers - One sensitive and one not sensitive.

0 Votes 0 ·