Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Prabhu_K
Starting Member
2 Posts |
Posted - 2012-08-05 : 09:00:46
|
Hi,I have a requirement, where I need to add the decimals to a column based on the precision/values stored in another column.Ex:COL1 COL2 COL3135 141 1NULL 0.1 3NULL 4 2I need to use COL3 decimal precision and convert the columns 1 and 2 with the right value.In above case, The result should look like below.COL1 COL2 COL3135.0 141.0 1NULL 0.100 3NULL 4.00 2Please let me know any function which can do this or any other option.Please reply ASAP.With best RegardsPrabhu |
|
Prabhu_K
Starting Member
2 Posts |
Posted - 2012-08-05 : 12:35:13
|
Any updates please!!With best RegardsPrabhu |
 |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-08-05 : 13:54:31
|
As precision is part of data type, when defined, so possibly it would be hard to do that as a batch. But still you can do it through cursor and dynamic query.DECLARE @Str VARCHAR(500)SELECT @Str = 'SELECT CAST(COL1 AS DECIMAL (18,'+CAST (@COL3 AS VARCHAR(10))+')) AS COL1, CAST(COL2 AS DECIMAL (18,'+CAST(@COL3 AS VARCHAR(10))+')) AS COL2 FROM #Test' EXEC (@Str)--------------------------http://connectsql.blogspot.com/ |
 |
|
|
|
|