--create a stored procedureCreate procTest_proc@date datetime as Select * fromT_userwhere TimesbetweenConvert(datetime,CONVERT(varchar(Ten),DATEPART(YYYY,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(MM,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(DD,@date))+ CONVERT(varchar(Ten),' the')) andConvert(datetime,CONVERT(varchar(Ten),DATEPART(YYYY,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(MM,@date))+'-' + CONVERT(varchar(Ten),DATEPART(DD,@date))+ CONVERT(varchar(Ten),'22:00'))Go--Modifying stored ProceduresAlter proctest_1@date datetime as Select Count(1) fromT_userwhere TimesbetweenCONVERT(varchar(Ten),DATEPART(YYYY,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(MM,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(DD,@date))+ CONVERT(varchar(Ten),' the') andCONVERT(varchar(Ten),DATEPART(YYYY,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(MM,@date))+ '-' + CONVERT(varchar(Ten),DATEPART(DD,@date))+ CONVERT(varchar(Ten),'22:00')Go--Executing stored proceduresexecTest_proc'2012-3-4'--using variables to receive return valuesDeclare @return_value int exec @return_value=Test_1'2012-3-4'Select @return_value
Simple use of SQL Server stored procedures