November 11, 2013

SQLSaturday 248 BI Edition Tampa 2013

I have a great time on SQLSaturday 248 Bi edition on Tampa. Jose Chinchilla knows how to be an excellent host, there was plenty of food on both the SQLSaturday Speaker dinner and in the event lunch hours.
Both of my sessions when very smoothly and the this time I have many students for FSU.
Now back to coding....Here is a function that will convert an numeric string into a Comp3 format hex representation:

CREATE FUNCTION [dbo].[udf_Comp3Format]
(
  @NumericStr varchar(50)
  
)
RETURNS varchar (50)
AS
BEGIN
-- Declare the return variable here
Declare @Pos varchar(1)
Declare @Neg varchar(1)
Declare @Unsg varchar (1)
Declare @Sign varchar(1)
Declare @IntVal numeric
declare @value varchar (1024)

Set @Pos = 'C' -- Positive
Set @Neg = 'D' -- Negative 
Set @Unsg = 'F' -- Unsign
if TRY_PARSE (@NumericStr as numeric) is not null
begin  
select @IntVal = parse (@NumericStr as numeric)

--Remove +- sign or - sign 
select @value = ltrim (rtrim (replace (replace (replace (cast (@NumericStr as varchar(50)),'+-','-'),'-',''),'.','')))

--Add Sign 
if (@IntVal < 0)
set @value = @value+@Neg
else
set @value = @value+@Pos

if (len(@value)%2= 1)
set @value = '0'+@value
end 
      else
   set @value = NULL

RETURN @value

END

No comments:

Post a Comment

Contact Form

Name

Email *

Message *