Wednesday, March 7, 2012

decimal question

I am working on a bcp table dump. I have a column that has a numeric value
with 2 decimals. Is there to have the result file show no decimals if there
is no value in this table. Right now, it looks like
123.45
0.00
123.45
0.00
I would like it to look like :
123.45
0
123.45
0
I know the value is the same, but I still have a need to accomplish this.
Thanks in advancecast it to a varchar.
set nocount on
declare @.table table (value numeric (6,2))
insert into @.table values (123.45)
insert into @.table values (0.00)
insert into @.table values (123.45)
insert into @.table values (0.00)
select case when value = 0 then '0'
else str(value,6,2) end as value
from @.table
What if the value is 123.40, what then?
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"TJBowens" <TJBowens@.msn.com> wrote in message
news:OXTJVPWNFHA.3620@.TK2MSFTNGP10.phx.gbl...
>I am working on a bcp table dump. I have a column that has a numeric value
>with 2 decimals. Is there to have the result file show no decimals if
>there is no value in this table. Right now, it looks like
> 123.45
> 0.00
> 123.45
> 0.00
> I would like it to look like :
> 123.45
> 0
> 123.45
> 0
> I know the value is the same, but I still have a need to accomplish this.
> Thanks in advance
>|||123.40
"Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
news:eunvFyXNFHA.4028@.tk2msftngp13.phx.gbl...
> cast it to a varchar.
> set nocount on
> declare @.table table (value numeric (6,2))
> insert into @.table values (123.45)
> insert into @.table values (0.00)
> insert into @.table values (123.45)
> insert into @.table values (0.00)
> select case when value = 0 then '0'
> else str(value,6,2) end as value
> from @.table
> What if the value is 123.40, what then?
> --
> ----
--
> Louis Davidson - drsql@.hotmail.com
> SQL Server MVP
> Compass Technology Management - www.compass.net
> Pro SQL Server 2000 Database Design -
> http://www.apress.com/book/bookDisplay.html?bID=266
> Blog - http://spaces.msn.com/members/drsql/
> Note: Please reply to the newsgroups only unless you are interested in
> consulting services. All other replies may be ignored :)
> "TJBowens" <TJBowens@.msn.com> wrote in message
> news:OXTJVPWNFHA.3620@.TK2MSFTNGP10.phx.gbl...
>|||So this will do what you want then, right?
I assume 123.40 was the answer to my question :)
--
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"TJBowens" <TJBowens@.msn.com> wrote in message
news:uyYVMNfNFHA.688@.TK2MSFTNGP10.phx.gbl...
> 123.40
> "Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
> news:eunvFyXNFHA.4028@.tk2msftngp13.phx.gbl...
>

No comments:

Post a Comment