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