Groups | Blog | Home
all groups > sql server clients > november 2004 >

sql server clients : bcp extract with , (comma) as decimal


grille11 NO[at]SPAM yahoo.com
11/18/2004 1:15:10 PM
Hello,

I am desperatly trying to export a table from my sql server.
Using bcp I only have my csv file with . as decimal for all numbers (I also
tried the export wizard of the sql console).
Is there a way to obtain these figures with a comma , as decimal?
The ddl of the table is below and numbers are stored in :

[number_value] [float]



CREATE TABLE [dbo].[table] (
[id] [int] NOT NULL ,
[id2] [int] NOT NULL ,
[date_lo] [smalldatetime] NOT NULL ,
[number_type] [int] NOT NULL ,
[is_estimated] [varchar] (2) NULL ,
[number_value] [float] NULL ,
[date_value] [smalldatetime] NULL ,
[string_value] [varchar] (255) NULL ,
[number_int_value] [int] NULL
) ON [PRIMARY]
GO


Thanks in advance for your help.


grille11 NO[at]SPAM yahoo.com
11/18/2004 2:48:26 PM
I have an error code: 0
description: Invalid use of Null: 'replace'

The first 40000 rows have a null value and the rest as a value with a
deciaml as .

Here is an example, the first row as no value and the one below has
1513.2527515762899 that need to be changed as 1513,2527515762899.


1;0;0;2004-02-27 00:00:00;3;0;N;;2004-02-27 00:00:00;;
1;1990;2;2003-01-09 00:00:00;5;0;N;1513.2527515762899;;;





[quoted text, click to view]

Mohamed Sharaf
11/18/2004 2:58:29 PM
You can try DTS and edit the default transformation script to be like this

Function Main()
DTSDestination("id") = DTSSource("id")
DTSDestination("id2") = DTSSource("id2")
DTSDestination("date_lo") = DTSSource("date_lo")
DTSDestination("number_type") = DTSSource("number_type")
DTSDestination("is_estimated") = DTSSource("is_estimated")
DTSDestination("number_value") = replace(DTSSource("number_value"),".",",")
' Do replacement here
DTSDestination("date_value") = DTSSource("date_value")
DTSDestination("string_value") = DTSSource("string_value")
DTSDestination("number_int_value") = DTSSource("number_int_value")
Main = DTSTransformStat_OK
End Function

Is this what you need?

Thanks,
--
Mohamed Sharaf
MEA Developer Support Center
ITWorx on behalf Microsoft EMEA GTSC


[quoted text, click to view]

Mohamed.Sharaf NO[at]SPAM egdsc.microsoft.com (
11/22/2004 9:29:23 AM
Hello,
This error happens because of null values so we can change the code
to become
Function Main()
DTSDestination("id") = DTSSource("id")
DTSDestination("id2") = DTSSource("id2")
DTSDestination("date_lo") = DTSSource("date_lo")
DTSDestination("number_type") = DTSSource("number_type")
DTSDestination("is_estimated") = DTSSource("is_estimated")
if DTSSource("number_value")<>"" then
DTSDestination("number_value") =
replace(DTSSource("number_value"),".",",") ' Do replacement here
end if
DTSDestination("date_value") = DTSSource("date_value")
DTSDestination("string_value") = DTSSource("string_value")
DTSDestination("number_int_value") = DTSSource("number_int_value")
Main = DTSTransformStat_OK
End Function

I didn't try this code , so it may still needs some modifications, please
try it.

Best regards,
Mohamed Sharaf
MEA Developer Support Center
ITWorx on behalf Microsoft EMEA GTSC
AddThis Social Bookmark Button