SQL Server R2 Several custom functions

Source: Internet
Author: User

1 --string turns into time2  GO3 CREATE FUNCTION [dbo].[Jbfs_ms_varchar_to_datetime](@strDate varchar( -)4 )5 RETURNS datetime6  as7 BEGIN8   Declare @tmpTm datetime9   Set @tmpTm =CONVERT(datetime,@strDate);Ten   RETURN @tmpTm; One END A --time turns into a string - GO - CREATE FUNCTION [dbo].[Jbfs_ms_datetime_to_varchar](@date datetime,@inputNum int the ) - RETURNS varchar( -) -  as - BEGIN +   Declare @strTm varchar( -) -   Set @strTm =CONVERT(varchar( -),@date,@inputNum); +   RETURN @strTm; A END at --currency conversion thousand-bit string -  - CREATE function [dbo].[Jbfs_ms_money_to_varchar](@dec  Money,@n int) - returns varchar( +) as - begin -     Declare @str varchar( +),@len int,@left varchar( +),@right varchar( +),@end varchar( +) in     if @n!='0' -     begin to         --Rounding +        Set @str= round(@dec,@n) -        Select @left=left(@str,charindex('.',@str)-1),@len=Len(@left)-2 the         while @len>1 *        begin $            Select @left=Stuff(@left,@len,0,','),@len=@len-3Panax Notoginseng        End -        Select @right=left(Stuff(@str,1,charindex('.',@str),"'),@n),@len=4 the         while @len <=Len(@right) +        begin A            Select @right=Stuff(@right,@len,0,','),@len=@len+4 the        End +        Set @end= @left+'.'+@right -     End $     Else $     begin -        Set @str= round(@dec,@n) -        Select @left=left(@str,charindex('.',@str)-1),@len=Len(@left)-2 the         while @len>1 -        beginWuyi            Select @left=Stuff(@left,@len,0,','),@len=@len-3 the        End -        Select @right=left(Stuff(@str,1,charindex('.',@str),"'),@n),@len=4 Wu         while @len <=Len(@right) -        begin About            Select @right=Stuff(@right,@len,0,','),@len=@len+4 $        End -        Set @end= @left -     End -     return @end A End + --string converted to Money the CREATE function [dbo].[Jbfs_ms_varchar_to_money](@dec varchar( -)) - returns  Money  $     as the BEGIN the     DECLARE @mon  Money the     SET @mon =cast(@dec  as  Money) the  return @mon - END

SQL Server R2 Several custom functions

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.