ALTER FUNCTION [dbo].[fn_ConvertToSmallDateTime](@Val varbinary(4))
RETURNs SmallDateTime
AS
BEGIN
RETURN CONVERT(SmallDateTime,SUBSTRING(@Val,4,1)
+SUBSTRING(@Val,3,1)
+SUBSTRING(@Val,2,1)
+SUBSTRING(@Val,1,1) )
END
ALTER FUNCTION [dbo].[fn_ConvertToDateTime](@Val varbinary(8))
RETURNs datetime
AS
BEGIN
RETURN CONVERT(DATETIME,SUBSTRING(@Val,8,1)
+SUBSTRING(@Val,7,1)
+SUBSTRING(@Val,6,1)
+SUBSTRING(@Val,5,1)
+SUBSTRING(@Val,4,1)
+SUBSTRING(@Val,3,1)
+SUBSTRING(@Val,2,1)
+SUBSTRING(@Val,1,1) )
END
ALTER FUNCTION [dbo].[fn_ConvertToDate](@Val varbinary(4))
RETURNs Date
AS
BEGIN
RETURN CONVERT(Date,@Val)
END
ALTER FUNCTION [dbo].[fn_ConvertToTime](@Val varbinary(5))
RETURNs Time
AS
BEGIN
RETURN CONVERT(Time,0x07+@Val)
END
ALTER FUNCTION [dbo].[fn_ConvertToChar](@Val Varbinary(max))
RETURNS CHAR(8000)
AS
BEGIN
RETURN CONVERT(CHAR(8000),@Val)
END
ALTER FUNCTION [dbo].[fn_ConvertToNChar](@Val Varbinary(max))
RETURNS NCHAR(4000)
AS
BEGIN
RETURN CONVERT(NCHAR(4000),@Val)
END
ALTER FUNCTION [dbo].[fn_ConvertToNVarchar](@Val varbinary(max))
RETURNS Nvarchar(max)
AS
BEGIN
RETURN CONVERT(NVARCHAR(max),@val)
END
ALTER FUNCTION [dbo].[fn_ConvertToVarchar](@Val varbinary(max))
RETURNS varchar(4000)
AS
BEGIN
RETURN CONVERT(VARCHAR(4000),@val)
END
ALTER FUNCTION [dbo].[fn_ConvertToBigInt](@Val varbinary(8))
returns BIGINT
begin
return convert(bigint,substring(@Val,8,1)
+substring(@Val,7,1)
+substring(@Val,6,1)
+substring(@Val,5,1)
+substring(@Val,4,1)
+substring(@Val,3,1)
+substring(@Val,2,1)
+substring(@Val,1,1)
)
end
ALTER FUNCTION [dbo].[fn_ConvertToInt](@Val VARBINARY(4))
RETURNS INT
AS
BEGIN
RETURN convert(int,substring(@Val,4,1)+substring(@Val,3,1)+substring(@Val,2,1)+substring(@Val,1,1))
END
ALTER FUNCTION [dbo].[fn_ConvertTosmallInt](@Val varbinary(4))
returns smallInt
begin
return convert(SMALLINT,SUBSTRING(@Val,4,1)
+substring(@Val,3,1)
+substring(@Val,2,1)
+substring(@Val,1,1)
)
end
ALTER FUNCTION [dbo].[fn_ConvertToSmallMoney](@Val varbinary(4))
RETURNs SmallMoney
AS
BEGIN
RETURN CONVERT(SmallMoney,SUBSTRING(@Val,4,1)
+SUBSTRING(@Val,3,1)
+SUBSTRING(@Val,2,1)
+SUBSTRING(@Val,1,1) )
END
ALTER FUNCTION [dbo].[fn_ConvertTotinyint](@Val varbinary(1))
returns tinyint
begin
return convert(tinyint, @Val)
end
ALTER FUNCTION [dbo].[fn_ConvertToMoney](@Val varbinary(8))
RETURNs Money
AS
BEGIN
RETURN CONVERT(Money,SUBSTRING(@Val,8,1)
+SUBSTRING(@Val,7,1)
+SUBSTRING(@Val,6,1)
+SUBSTRING(@Val,5,1)
+SUBSTRING(@Val,4,1)
+SUBSTRING(@Val,3,1)
+SUBSTRING(@Val,2,1)
+SUBSTRING(@Val,1,1) )
END
ALTER FUNCTION [dbo].[fn_ConvertToBit](@Val VARBINARY(4))
RETURNS BIT
AS
BEGIN
RETURN convert(BIT,substring(@Val,4,1))
END
ALTER FUNCTION [dbo].[fn_ConvertToNumeric](@Val varbinary(38),@P NVARCHAR(10),@S NVARCHAR(10) )
RETURNs NVARCHAR(50)
AS
BEGIN
DECLARE @X NVARCHAR(4000)
SET @X='CONVERT(NUMERIC('+@P+','+@S+'), CONVERT(VARBINARY(1),'+@P+')+CONVERT(VARBINARY(1),'+@S+')+0x00+'+sys.fn_varbintohexstr(@Val)+')'
RETURN CONVERT(NVARCHAR(50), dbo.myCacl(@X,1))
END
ALTER FUNCTION [dbo].[fn_ConvertToDECIMAL](@Val varbinary(38),@P NVARCHAR(10),@S NVARCHAR(10))
RETURNs NVARCHAR(50)
AS
BEGIN
DECLARE @X NVARCHAR(4000)
SET @X='CONVERT(DECIMAL('+@P+','+@S+'), CONVERT(VARBINARY(1),'+@P+')+CONVERT(VARBINARY(1),'+@S+')+0x00+'+sys.fn_varbintohexstr(@Val)+')'
RETURN CONVERT(NVARCHAR(50), dbo.myCacl(@X,1))
END
ALTER FUNCTION [dbo].[fn_ConvertTouniqueidentifier](@Val varbinary(16))
RETURNs uniqueidentifier
AS
BEGIN
RETURN CONVERT(uniqueidentifier,@Val)
END
ALTER Function [dbo].[ft_GetNullBitMap](@Val varbinary(50),@P INT )
RETURNS @Rst TABLE(num int)
AS
BEGIN
DECLARE @i INT =0
DECLARE @Str VARCHAR(20)=''
DECLARE @R VARCHAR(4000)=''
DECLARE @Tmp VARBINARY(4)
DECLARE @J INT =@P
WHILE @j>=1
BEGIN
SET @Tmp=SUBSTRING(@val,@J-2,2)
SET @i =dbo.fn_ConvertToInt(@Tmp)
set @Str =dbo.ConvertDecToX(@I,2)
IF LEN(@Str)<8
BEGIN
SET @Str=REPLICATE('0',8-LEN(@Str))+@Str
END
SET @R=@R+@Str
SET @J=@J-2
END
SET @R=REVERSE(@R)
SET @I=1
WHILE @I<=LEN(@R)
BEGIN
IF SUBSTRING(@R,@I,1)=1
BEGIN
INSERT INTO @Rst VALUES(@I)
End
SET @I=@I+1
End
RETURN
END
/*
以下CLR函数
[SqlFunction]
public static Single Fn_ConvertToSingle(byte[] x)
{
return BitConverter.ToSingle(x, 0);
}
[SqlFunction]
public static double Fn_ConvertToDouble(byte[] x)
{
return BitConverter.ToDouble(x, 0);
}
[SqlFunction]
public static string ConvertDecToX(int Val, int X)
{
return Convert.ToString(Val, X).ToUpper();
}
[SqlFunction]
public static Int32 ConvertXToDec(string Val, int X)
{
return Convert.ToInt32(Val, X);
}
*/