| Author |
Topic |
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 08:08:02
|
| Guys is therea way by which I can set the precision of a Decimal type dynamically.ex Isnull(Cast(Reading as Decimal(18,some variable)),0.00)Thnx |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-06-11 : 08:14:42
|
| why would you want to?what type is Reading originally?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 08:50:51
|
| Because on the page the user wants to set it dynamically.Suppose he sets the value say @precision=2then all the readings values during display should have a maximum precision to 2 values no matter what the exact values are. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-11 : 08:52:58
|
| Use Dynamic SQL to achieve ur goal!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 08:56:30
|
quote: Originally posted by senthil_nagore Use Dynamic SQL to achieve ur goal!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
Thats exactly what I want to prevent.If that is the only resource left then unfortunately I will have to use that.But just wanted to know is there any other better way except dsql to achieve it. |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-06-11 : 09:03:41
|
| if you are talking about the precision of data in a table you can go changing it :) but you really don't want to it will affect all the data in the column if your save your data in a table it will always be converted to column precision, don't bother if you use your data for calculation only just change the precision of result in the output field |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-11 : 09:03:59
|
maybe just use case statement ? well . . the most is you going to have 18 when condition . . KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 09:08:57
|
quote: Originally posted by asgast if you are talking about the precision of data in a table you can go changing it :) but you really don't want to it will affect all the data in the column if your save your data in a table it will always be converted to column precision, don't bother if you use your data for calculation only just change the precision of result in the output field
I am not going to change in the table.The column datatype will be decimal with precision of 10.The user wants decides till what precision he wants to see the readings. |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-06-11 : 09:17:37
|
| just change the precision on the page not in the sqlif you really need it try:DECLARE @n nvarchar(max)DECLARE @r decimal(38,36)DECLARE @p nvarchar(100)SET @n = 'SELECT CAST(@r AS decimal('+CAST(@pr AS VARCHAR)+','+CAST(@pr-1 AS VARCHAR)+'))'SET @p = '@r decimal(38,36)'EXEC sp_executesql @n, @p, @r@pr is our precision |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 09:23:30
|
| So I guess there is no other way except for dynamic sql. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-11 : 09:31:22
|
quote: Originally posted by ayamas So I guess there is no other way except for dynamic sql.
how about doing on the page as what others has suggested ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-11 : 09:44:55
|
quote: Originally posted by khtan
quote: Originally posted by ayamas So I guess there is no other way except for dynamic sql.
how about doing on the page as what others has suggested ? KH[spoiler]Time is always against us[/spoiler]
Who & where??? |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-06-11 : 10:05:55
|
quote: Originally posted by ayamas
quote: Originally posted by khtan
quote: Originally posted by ayamas So I guess there is no other way except for dynamic sql.
how about doing on the page as what others has suggested ? KH[spoiler]Time is always against us[/spoiler]
Who & where???
I have, twice :)SQL is for data manipulation not for setting comas in the right place :) |
 |
|
|
|