miércoles, 12 de agosto de 2009

Procesos almacenados en SQL Server 2005

En SQL Server 2005 podemos declarar stored procedures de la siguiente manera:


/***** DATASET *****/
USE [DatabaseName]
GO
/****** Object: StoredProcedure [dbo].[MyStoredProcedure] Script Date: mm/dd/yyyy hh:mm:ss ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MyStoredProcedure]
@fromDate datetime,
@toDate datetime
AS
BEGIN
DECLARE @@realToDate datetime
SET @@realToDate = dateadd(day, 1, @toDate)
Select ......... From ........ where LocalDateTime >= @fromDate and LocalDateTime < @@realToDate) .... order by ....
END


Luego podemos ejecutarlo así:

EXEC DatabaseName.dbo.MyStoredProcedure @fromDate='08/10/2009', @toDate='08/10/2009'

No hay comentarios: