I'm using SQL Server 2005, and want a user defined function to implement the following:
Parameter: @SQL varchar(max)
execute 'select count(1) from (' + @sql + ')'
and return the result as integer.
This is the dummy code >>
ALTER FUNCTION [dbo].udf_GetCountFromSQL ( @SQL VARCHAR(MAX) )
RETURNS INT
AS
BEGIN
DECLARE @returnValue INT
SET @SQL = 'SELECT COUNT(1) FROM (' + @SQL + ')'
EXEC @returnValue= @SQL
RETURN @returnValue ;
END
@SQL here is dynamic sql, not stored procedure name, so it doesn't work.
Wait to be helped out, thanks in advance.
Elaine