SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error converting data type varchar to bigint.


Error converting data type varchar to bigint.

Author
Message
lu - Si
lu - Si
SSC-Enthusiastic
SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)

Group: General Forum Members
Points: 112 Visits: 35
Hi

Can someone help me... i get the error ---> Error converting data type varchar to bigint.
when i write the code below

thanks in advance

Regards,



sqlcmd = "Create table #Eft_Transfer( " & vbCrLf _
& " EFT_No varchar(20), null , " & vbCrLf _
& " Effective_Date datetime , " & vbCrLf _
& " Service_Code Varchar(10) , " & vbCrLf _
& " Reference_Number Varchar(30)) " & vbCrLf

With grdCreateGrid
For lngRowCount = 1 To .MaxRows
.GetText(ConstgrdCEftNum, lngRowCount, varValue)
strEftNo = varValue
.GetText(constgrdCEffectiveDte, lngRowCount, varValue)
strDate = varValue
.GetText(constgrdCServiceCodeCode, lngRowCount, varValue)
strCode = varValue
.GetText(constgrdCRefNo, lngRowCount, varValue)
strReference = varValue

sqlcmd = sqlcmd & _
" insert into #Eft_Transfer values ('" & strEftNo & "','" & strDate & "','" & strCode & "','" & strReference & "')" & vbCrLf
Next lngRowCount
End With

sqlcmd = sqlcmd & "Execute TransferFileCreate '" & txtFileName.Text & "'" & vbCrLf _
& "Drop Table #Eft_Transfer"

' Debug.Print sqlcmd
' GoTo ErrorHandler
If objGeneral.Execute32(sqlcmd, SqlResults, SqlDataRowss, False, False, True) <> -1 Then GoTo ErrorHandler
HanShi
HanShi
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18700 Visits: 3791
I assume the error is genereated in the following line (can you confirm?)
sqlcmd = sqlcmd & _
" insert into #Eft_Transfer values ('" & strEftNo & "','" & strDate & "','" & strCode & "','" & strReference & "')" & vbCrLf

The error indicates a string value is entered in a field (or variable) with the BIGINT datatype. It looks like one of your string-values doesn't contain a value that can be converted to a integer vale. To troubleshoot you can print the values just before inserting them. That way you can manually check if the values are correct.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
lu - Si
lu - Si
SSC-Enthusiastic
SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)

Group: General Forum Members
Points: 112 Visits: 35
Thanks for responding

Yes the error happens there

it does get the correct value
which is : strEFTNo = 'EFT0000000220'

But i wants this as numeric

and my
SELECT ISNUMERIC('EFT0000000220')
Results = 0 instead of 1

i tried casting and converting the strEft but i haven't come right
David Burrows
David Burrows
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32027 Visits: 10712
You cannot cast 'EFT0000000220' to bigint.
You can cast the numerical part, ie CAST(SUBSTRING('EFT0000000220',4,10) as bigint)


Far away is close at hand in the images of elsewhere.

Anon.


HanShi
HanShi
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18700 Visits: 3791
David Burrows (1/14/2014)
You cannot cast 'EFT0000000220' to bigint.
You can cast the numerical part, ie CAST(SUBSTRING('EFT0000000220',4,10) as bigint)

What David is saying: the text part "EFT" can not be converted to a numeric value. Therefor you have to remove these characters from the value (using the SUBSTRING function). The remaing text represents a value tht can be converted to a numeric (BIGINT) value.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
patrickmcginnis59 10839
patrickmcginnis59 10839
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9764 Visits: 6708
In this snippet:

sqlcmd = "Create table #Eft_Transfer( " & vbCrLf _
& " EFT_No varchar(20), null , " & vbCrLf _
& " Effective_Date datetime , " & vbCrLf _
& " Service_Code Varchar(10) , " & vbCrLf _
& " Reference_Number Varchar(30)) " & vbCrLf


you have an extra comma between the "EFT_No varchar(20)" and "null" and that might create unexpected results. That might just have been an error in posting though!

to properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
David Burrows
David Burrows
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32027 Visits: 10712
patrickmcginnis59 10839 (1/14/2014)
In this snippet:

sqlcmd = "Create table #Eft_Transfer( " & vbCrLf _
& " EFT_No varchar(20), null , " & vbCrLf _
& " Effective_Date datetime , " & vbCrLf _
& " Service_Code Varchar(10) , " & vbCrLf _
& " Reference_Number Varchar(30)) " & vbCrLf


you have an extra comma between the "EFT_No varchar(20)" and "null" and that might create unexpected results. That might just have been an error in posting though!


Yes otherwise the sql would fail in parsing not execution, notwithstanding, the code and sql is OK.
I suspect the error is in the procedure TransferFileCreate


Far away is close at hand in the images of elsewhere.

Anon.


lu - Si
lu - Si
SSC-Enthusiastic
SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)

Group: General Forum Members
Points: 112 Visits: 35
Thanks so much for all responses and your help
Problem solved.......
:-D:-D:-D:-D.........
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search