Welcome! Log In Create A New Profile

Advanced

[WD12] Query to change part of a field

Posted by Louis Verbraak 
Louis Verbraak
[WD12] Query to change part of a field
September 30, 2008 04:30PM
Hello,

Can anybody tell me if there is a possiblity to change part of a field with a query. I've the field 'Sorteerveld' in which the first 4 position are the year. Is there a way to change a number of these records at once by using a query. Something like:

UPDATE
____MyFile
SET
____Sorteerveld = {iYear] + Sorteerveld[[5 to]]
WHERE
____MyFile.Year = {iYear}

I hope someone can help me.
Georgio
Re: [WD12] Query to change part of a field
September 30, 2008 10:30PM
Hi Louis,

The easiest way I can think of doing this is using 2 queries. (a select & an update query).

First, use your select query to find the record that you are looking for.
Then use the update query to update the data.

Something like.

MySelectQuery.pParam = sMyParam
HExecuteQuery(MySelectQry,hQueryDefault)
HReadFirst(MySelectQry)

While Hfound(MySelectQry)
sWhatToChange = iYear + MySelectQry.FIELD[[5 to]
nQryRecID = MySelectQry.RECID

MyUpdateQuery.vRecId = nQryRecID
MyUpdateQuery.pFIELD = sWhatToChange
HexecuteQuery(MyUpdateQuery,hQueryDefault)
HreadNext(MySelectQry)
...

Mind you, I wrote this directly into the editor, so there may be errors and I
didn't trap errors on the HexecuteQuery commands.

I'm not sure how many records you are doing this with nor how CPU intensive
this would be if there are lots of records. I like using the Windev Query editor
instead of SQL commands and its always pretty fast for me.

Georgio
Louis Verbraak
Re: [WD12] Query to change part of a field
October 01, 2008 08:39AM
Hello Georgio,

Thanks for your answer. I hoped there was a way by using only one query.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: