importing data from excel

  • I have a SP that gets data from parameters in Asp.net the .net form passes data from an excel spreadsheet.

    This all works except that when it inserts any of the fields that contain numbers they end up in sql looking like 9.37123e+009 or 4.581e+008

    I have tried cast and convert to no avail.

    I believe SQL is seeing the the incoming numeric data as float

    even though i have the data in excel as general or text.

    If I do an implicit conversion I get an error saying cannot convert float to nvarchar or nchar I have tried both formats.

    I am at a loss right now

    here is my sp (I know everything may not be best practice, but this is the hand I was dealt, I didn't create the DB or SP)

    ALTER PROCEDURE [dbo].[mySP]

    @FirstName nchar(255),

    @HomeAddress nvarchar(256),

    @HomeCity nvarchar(256),

    @HomeState nvarchar(256),

    @HomeZIP nchar(255),

    @HomePhone nchar(50),

    @RoleName varchar(256)

    AS

    Begin

    Set NoCount on

    Declare @TelephoneID int

    Select @TelephoneID = Count(TelephoneID)+1 from app_TelephoneDetails

    Insert into app_TelephoneDetails (TelephoneID, Telephone,

    FirstName, RoleName,

    HomeAddress,HomeCity,

    HomeState,HomeZIP,

    HomePhone,LastModified,

    StatusCode, LastUser,Active)

    values

    (@TelephoneID, CAST(@HomePhone AS nvarchar(50)),

    @FirstName,@RoleName,

    @HomeAddress,@HomeCity,

    @HomeState,CAST(@HomeZip AS nvarchar(50)),CAST(@HomePhone AS nvarchar(50)),

    { fn NOW() }, 'Open', 'admin', -1)

    End

  • Try converting to bigint first.

    SELECT CAST(CAST(9.37123e+009 AS bigint) AS nvarchar(50))

     

  • Nope Now get Error converting data type nvarchar to bigint

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply