question

user-1280 (google) avatar image
user-1280 (google) asked

how to rewrite function from vb6 to sqlsever function and how call it

Public Function ItemMCost1(ByVal ItmCod As String, ByVal SizeCode As Long) As Double

Dim Dy As Recordset Dim Sql As String Dim MCost As Double Dim Quant As Double

MCost = 0 Quant = 0

Sql = "SELECT DocType ,Quntity ,Price FROM ItemTran" & Chr(13) Sql = Sql & " WHERE ItemCode = '" & Trim$(ItmCod) & "'" & Chr(13) Sql = Sql & " AND SizeCode = " & Trim$(SizeCode) & Chr(13) Sql = Sql & " ORDER BY DocDate" Set Dy = DB1.OpenRecordset(Sql, 2) If Not Dy.EOF Then Dy.MoveFirst While Not Dy.EOF Select Case Dy("DocType") Case 1, 2, 8 If Quant + Dy("Quntity") <> 0 Then MCost = ((Quant * MCost) + (Dy("Quntity") * Dy("Price"))) / (Quant + Dy("Quntity")) Quant = Quant + Dy("Quntity") Else MCost = 0 Quant = 0 End If Case Else Quant = Quant + Dy("Quntity") End Select Dy.MoveNext Wend End If Dy.Close Set Dy = Nothing ItemMCost = MCost End Function

user-defined-function
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sorry, this is not readable. you can format the code by selecting it and clicking 'code sample' icon.
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.