Click to See Complete Forum and Search --> : VB


Savitha S
August 16th, 2001, 02:32 AM
I need some help on calling a user defined function written in vb,in sql through ADO.
I have written a function call removezipcode() in vb.
I need to call this in a batch update statement.
eg.
adoconnect.execute "update table1 set column1=removezipcode(column1)"
It is not recognizing the removezipcode() function.

Gek
August 16th, 2001, 02:44 AM
try:


strSQL = "SELECT column1 FROM table1"
set rec1 = con1.execute(strSQL) ' or something like that

do while not rec1.eof
strSQL = "UPDATE table1 set column1=" & removezipcode(rec1!column1)
call con1.execute(strSQL)
rec1.movenext
loop

rec1.close

Gek
August 16th, 2001, 02:48 AM
uups, don't forget the where clause in the update statement like I did.

Daniel

remcoploeg
August 16th, 2001, 03:56 AM
The where code has also a variable. So where do I put the where code with the variable???

Remco Ploeg
ploegr@promar-agencies.nl

Sephozzy
August 16th, 2001, 03:58 AM
Try this:


Dim SQL as string
SQL = "update table1 set column1 = '" & removezipcode & "'"
adoconnect.execute(SQL)




Don't forget the ' if you're working with text.

Sephozzy
August 16th, 2001, 04:00 AM
Try this:


Dim SQL as string
SQL = "update table1 set column1 = '" & removezipcode(column1) & "'"
adoconnect.execute(SQL)




Don't forget the ' if you're working with text. (the colorcoding in the forum makes you think it's a comment but it actually works.

Savitha S
August 16th, 2001, 04:20 AM
Thank You for your replay.
But, I had written this code.
But the problem with this code is it consumes lot of time as it has to move through the recordset.
I need a solution where I need not move through the recordset

arunnura
August 16th, 2001, 04:22 AM
hai savi
this was the command u used
**********
adoconnect.execute "update table1 set column1=removezipcode(column1)"
***********
use as follow
*********
if the function returns a string then use this

adoconnect.execute "update table1 set column1='" & removezipcode(column1) & "'"



if the function returns a number then use this

adoconnect.execute "update table1 set column1= " & removezipcode(column1)



********

reply
arun,madhan,sathish

Savitha S
August 16th, 2001, 04:26 AM
Thank You,
The problem with this code is it recognizes column1 as a variable and not a field in the table.
I have written code to extract the zipcode from the address which is the function removezipcode.
what i'm trying to do is to pass the data in column1 as an argument to the function and extract the zipcode and update to the column1

Gek
August 16th, 2001, 05:43 AM
your table hopefully has a unique key. then you can try the following:


strSQL = "SELECT column1, ID FROM table1"
set rec1 = con1.execute(strSQL) ' or something like that

do while not rec1.eof
strSQL = "UPDATE table1 set column1=" & _
removezipcode(rec1!column1) & " WHERE ID=" & rec1!ID
call con1.execute(strSQL)
rec1.movenext
loop
rec1.close

Gek
August 16th, 2001, 05:46 AM
what dbms are your working with?
if it's sql server you could try to write a stored prozecure with the same functionality as "removezipcode".

Daniel