samedi 19 décembre 2015

How to create Decimal variable dynamically in sql server

DECLARE @Count INT = 4  --Actually this is calculated based on some logic but here i have hard coded it to keep it simple.

SET @Count = @Count + 10 --To accommodate Precision + Scale correctly

DECLARE @Temp DECIMAL( @Count , 10 ) -- I want something like this

I want to create a decimal variable in SQL Server whose Precession is taken from some variable dynamically, I have tried the above snippet but it fails with error 'Incorrect syntax near '@Count'.'

Is there any possible solution to do some thing like that ?

Aucun commentaire:

Enregistrer un commentaire