Link to home
Start Free TrialLog in
Avatar of Gowtham Ramamoorthy
Gowtham Ramamoorthy

asked on

How to Declare a global variable for storing the no.of .decimal values for a number(Variable)?

I tried with the following code its working but when i use insied a stored procedure its not working.. How can achieve this one  inside the stored procedure ?


CREATE TYPE phkTest from decimal(15,3)
GO


DECLARE @Foo phkTest

SET @Foo = 1
PRINT @Foo

SET @Foo = 1.1
PRINT @Foo

SET @Foo = 1.12
PRINT @Foo

SET @Foo = 1.123
PRINT @Foo
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America image

Try creating type outside stored procedure.
Avatar of Brian Crowe
The type must be created outside the scope of the stored procedure otherwise it cannot compile it.

Can you expand a little bit on what you are trying to accomplish and maybe we can help you find an alternative.
Avatar of Gowtham Ramamoorthy
Gowtham Ramamoorthy

ASKER

Hi Brian/Najam,

I have a  SP which start and End as shown below... I have various variable declarations where I have few 10's of varibles declared as a  decimal(15,3) which might change in the future also. So I created the global user defined type variable where in future if is want to change the variable to Decimal(15,2) it gets chnaged to all the defined variables.

As per your comment where should I exactly declare the user defined variables ?

Begin
Declaration part
{
Declare @variable Decimal(15,3).....
}
Code execution
Loop Ending
End
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial