Hi all! I want to create a stored procedure that returns a result based on the value of some DateTime parameters. Table format is:
CREATE TABLE [dbo].[Contracte](
[id] [int] IDENTITY(1,1) NOT NULL,
[NrContract] [int] NOT NULL,
[DataContract] [datetime] NOT NULL,
[idOrganizator] [int] NOT NULL,
[idExcursie] [int] NOT NULL,
[idUser] [int] NOT NULL,
CONSTRAINT [PK_Contracte] PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE PROCEDURE GetDocuments
@Date1 datetime = null
,@Date2 datetime = null
select * from [Contracte] where ?????
I need a query to show me the records whose DataContract are in the range @Date1 and @Date2, only if @Date1 and @Date2 are not null. If @Data1 and @Data2 are null, then you must return all records regardless of the date.
Thank you all!