Advertisement
Guest User

Untitled

a guest
May 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. --USE [Retribucions]
  2. --GO
  3. /****** Object: UserDefinedFunction [dbo].[converti] Script Date: 19/05/2019 23:25:21 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. --SELECT CAST( 4080 AS BINARY(4) )
  9. CREATE FUNCTION [dbo].[converti](@N bigint, @Base int)
  10.  
  11. RETURNS varchar(200)
  12. AS
  13. BEGIN
  14. -- Declaramos las variables a utilizar
  15. DECLARE @Result varchar(200),
  16. @NumChars varchar(50)
  17. -- Inicializamos las variables
  18. SET @NumChars = '0123456789ABCDEF'
  19. SET @Result = ''
  20. -- Validamos la base a convertir
  21. IF ( (@Base = 2) OR (@Base = 8) OR (@Base = 10) OR (@Base = 16) )
  22. BEGIN
  23. -- Ejecutamos el ciclo
  24. WHILE ( @N > 0 )
  25. BEGIN
  26. -- Realizamos la conversion
  27. SET @Result = SUBSTRING(@NumChars,(@N % @Base) + 1,1) + @Result
  28. --Disminuimos N, dividiendola entre la base
  29. SET @N = FLOOR(@N / @Base)
  30. END
  31. END
  32. --Retornamos el resultado
  33. RETURN @Result
  34. END
  35.  
  36.  
  37.  
  38.  
  39.  
  40. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement