views:

211

answers:

1

I have code similar to

Dim A, B, C
Set rs = Server.CreateObject("ADODB.Recordset")
strSql = "Exec [dbo].[some_sp] IND"
rs.open strSql,CN,3,3

Do While Not rs.EOF

'these columns are returned as decimal(10,2) format
A = rs("col1")
B = rs("col2")

rs.MoveNext
Loop

C = A + B 'i get type mismatch error here

And I used response.write to check values for A, B they are in integer format and not decimal

Do i have to format recordset again to set decimal values? And what could be possible problem for type mismatch as all values are integer (even if they are decimal) ?

+2  A: 

Variables in ASP/VBScript are just variant types so you may need to convert the values explicitly.

C = CDbl(A) + CDbl(B)

However, my guess would be that one of your rows does not have a numeric value for col1 or col2. Do you know what the values of those are when you get the type mismatch error?

Shawn Steward
Also, can the procedure ever return a NULL?
Sparky
yes i did response.write for all those values here is the result73, 0, 1, 0, 0, 0, 6I want them to be decimal before adding but they are in integer
rs
i figured it out. I used CDbl and it is working (Cdec will not work)
rs
Ah yeah that doesn't work in VBScript. I'll update my answer with your findings.
Shawn Steward