Obtain the unique Date and Time number. How to Write SQL Server Stored Procedures and functions?

Source: Internet
Author: User
Go/***** object: storedprocedure [DBO]. [e_get_datetimestrguid] script Date: 12/27/2012 15:07:38 ******/set ansi_nulls ongoset quoted_identifier ongo -- ================ =================================-- Author: <HSG> -- create Date: <2012-12-27> -- Description: <obtain the unique ID of a date and time> -- call method: Execute DBO. e_get_datetimestrguid; -- ===================================================== ====== alter procedure [DBO]. [e_get_datetimestrguid] -- add the parameters for the stored procedure hereasbegin -- set nocount on added to prevent extra result sets from -- interfering with select statements. -- declare the return variable heredeclare @ t_dt varchar (30); declare @ rd_num float; declare @ rd_str varchar (10 ); -- add the T-SQL statements to compute the return value hereset @ t_dt = convert (varchar, getdate (), 21); Set @ t_dt = Replace (@ t_dt ,'-', ''); Set @ t_dt = Replace (@ t_dt, ':',''); Set @ t_dt = Replace (@ t_dt ,'. ', ''); Set @ t_dt = Replace (@ t_dt ,'',''); -- return the result of the function -- generate an elliptical machine count select @ rd_num = floor (RAND () * 99999); Set @ rd_str = convert (varchar, @ rd_num ); -- merge a select @ t_dt + @ rd_str; End
/***** Object: userdefinedfunction [DBO]. [a_get_datetimestrguid] script Date: 12/27/2012 14:33:29 ******/set ansi_nulls ongoset quoted_identifier ongo -- ================ =================================-- Author: <HSG> -- create Date: <2012-12-27> -- Description: <obtain the unique ID of a date and time> -- call method: Select DBO. a_get_datetimestrguid (); -- ===================================================== ====== alter function [DBO]. [a_get_datetimestrguid] () returns varchar (30) asbegin -- declare the return variant heredeclare @ t_dt varchar (30); declare @ rd_num float; declare @ rd_str varchar (10 ); -- add the T-SQL statements to compute the return value hereset @ t_dt = convert (varchar, getdate (), 21); Set @ t_dt = Replace (@ t_dt ,'-', ''); Set @ t_dt = Replace (@ t_dt, ':',''); Set @ t_dt = Replace (@ t_dt ,'. ', ''); Set @ t_dt = Replace (@ t_dt,'', ''); -- return the result of the functionreturn @ t_dt; End
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.