Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/08/2009, 08:07
Avatar de Andres95
Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 20 años, 1 mes
Puntos: 38
Respuesta: Parámetros a Vista SQL

puedes generar una funcion que regrese un tipo tabla...


Código:
-- =============================================
-- Create table function (TF)
-- =============================================
IF EXISTS (SELECT * 
	   FROM   sysobjects 
	   WHERE  name = N'<table_function_name, sysname, test_function>')
	DROP FUNCTION <table_function_name, sysname, test_function>
GO

CREATE FUNCTION <table_function_name, sysname, test_function> 
	(<@param1, sysname, @p1> <data_type_for_param1, , int>, 
	 <@param2, sysname, @p2> <data_type_for_param2, , char>)
RETURNS <@table_variable_name, sysname, @table_var> TABLE 
	(<column_1, sysname, c1> <data_type_for_column1, , int>, 
	 <column_2, sysname, c2> <data_type_for_column2, , int>)
AS
BEGIN
	INSERT <@table_variable_name, sysname, @table_var>
	SELECT 1, 2
	RETURN 
END
GO

-- =============================================
-- Example to execute function
-- =============================================
SELECT * FROM <owner, , dbo>.<table_function_name, sysname, test_function>
	(<value_for_@param1, , 1>, 
	 <value_for_@param2, , 2>)
GO

Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.