How to execute dynamic SQL in the server (within stored procedures and triggers)
----------------------------------------------------------------------------------
ASE System 12 solution:
DECLARE @sqlstring varchar(255)
SELECT @sqlstring = "SELECT COUNT(*) FROM master..sysobjects"
EXEC (@sqlstring)
GO
ASE 11.5 and 11.9 solution utilizing the CIS features:
Firstly define your local server to be a remote server using
sp_addserver LOCALSRV,sql_server[,INTERFACENAME]
GO
Enable CIS
sp_configure "enable cis",1
GO
Finally, use sp_remotesql, sending the sql to the server defined in point 1.
DECLARE @sqlstring varchar(255)
SELECT @sqlstring = "SELECT COUNT (*) FROM master..sysobjects"
sp_remotesql LOCALSRV,@sqlstring
GO
ASE 10 solution (undocumented feature using stored procedures):
DECLARE @sqlstring varchar(255)
SELECT @sqlstring = "sp_who"
EXEC @sqlstring
GO
No comments:
Post a Comment