Skip to content

Instantly share code, notes, and snippets.

@ugurozpinar
Last active June 15, 2017 10:48
Show Gist options
  • Save ugurozpinar/66337906c16774255ed3ba318270b758 to your computer and use it in GitHub Desktop.
Save ugurozpinar/66337906c16774255ed3ba318270b758 to your computer and use it in GitHub Desktop.
Convert vba long color to rgb mssql functions
CREATE FUNCTION MODU ( @num int,@mod int)
RETURNS int
AS
BEGIN
DECLARE @numtmp int
IF @num<0
SET @numtmp = @num+(@mod*CEILING(ABS(CAST(@num AS FLOAT)/CAST(@mod AS FLOAT))))
ELSE
SET @numtmp = @num
RETURN(@numtmp % @mod)
END
GO
CREATE FUNCTION vbaColorToR(@color int)
RETURNS int
AS
BEGIN
RETURN(ABS(dbo.MODU(@color/(256*256),256)))
END
GO
CREATE FUNCTION vbaColorToG(@color int)
RETURNS int
AS
BEGIN
RETURN(ABS(dbo.MODU(@color/(256),256)))
END
GO
CREATE FUNCTION vbaColorToB(@color int)
RETURNS int
AS
BEGIN
RETURN(ABS(dbo.MODU(@color,256)))
END
GO
SELECT dbo.vbaColorToR(-9070348) AS R,dbo.vbaColorToG(-9070348) AS G,dbo.vbaColorToB(-9070348) AS B
-- R G B
--118 153 244
CREATE FUNCTION vbaColorToRGB(@color int)
RETURNS varchar(11)
AS
BEGIN
RETURN(CAST(dbo.vbaColorToR(@color) AS VARCHAR)+','+CAST(dbo.vbaColorToG(@color) AS VARCHAR)+','+CAST(dbo.vbaColorToB(@color) AS VARCHAR))
END
GO
SELECT dbo.vbaColorToRGB(-9070348)
-- 118,153,244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment