Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --USE [Retribucions]
- --GO
- /****** Object: UserDefinedFunction [dbo].[converti] Script Date: 19/05/2019 23:25:21 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- --SELECT CAST( 4080 AS BINARY(4) )
- CREATE FUNCTION [dbo].[converti](@N bigint, @Base int)
- RETURNS varchar(200)
- AS
- BEGIN
- -- Declaramos las variables a utilizar
- DECLARE @Result varchar(200),
- @NumChars varchar(50)
- -- Inicializamos las variables
- SET @NumChars = '0123456789ABCDEF'
- SET @Result = ''
- -- Validamos la base a convertir
- IF ( (@Base = 2) OR (@Base = 8) OR (@Base = 10) OR (@Base = 16) )
- BEGIN
- -- Ejecutamos el ciclo
- WHILE ( @N > 0 )
- BEGIN
- -- Realizamos la conversion
- SET @Result = SUBSTRING(@NumChars,(@N % @Base) + 1,1) + @Result
- --Disminuimos N, dividiendola entre la base
- SET @N = FLOOR(@N / @Base)
- END
- END
- --Retornamos el resultado
- RETURN @Result
- END
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement