473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

update groups of fields with sets of conditions

9
I have a query that I like to run in SQL format, but it's not getting corret results. This is to update multiple fields with multiple conditions. Should I be using VB to apply this type of update? My preference is to run the query using macro. Does anyone out there has any suggestions?

Here are sample codes:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TBLE_2 INNER JOIN TBLE_1
  2.     ON TBLE_2.part_no = TBLE_1.PART_NO
  3. SET    TBLE_2.prime_vendor_change = "Y"
  4.      , TBLE_2.prime_vendor_change_date = Date()-1
  5.      , TBLE_2.mod_code_change = "Y"
  6.      , TBLE_2.mod_code_change_date = Date()-1
  7.      , TBLE_2.release_date_change = "Y"
  8.      , TBLE_2.release_date_change_date = Date()-1
  9. WHERE ((TBLE_2.prime_vendor_change<>[TBLE_1].[PRM_SUPL_VNDR_ID])
  10.   AND  (TBLE_2.prime_vendor_change_date<>[TBLE_1].[PRM_SUPL_VNDR_ID])
  11.   AND  (TBLE_2.mod_code_change<>[TBLE_1].[PART_MOD_CD])
  12.   AND  (TBLE_2.mod_code_change_date<>[TBLE_1].[PART_MOD_CD])
  13.   AND  (TBLE_2.release_date_change<>[TBLE_1].[PART_REL_DATE])
  14.   AND  (TBLE_2.release_date_change_date<>[TBLE_1].[PART_REL_DATE]));
Nov 23 '11 #1
7 1692
NeoPa
32,556 Expert Mod 16PB
Please read [code] Tags Must be Used.

As far as the question goes, if you have a QueryDef then it doesn't matter greatly whether it's invoked via macro or VBA code. The same is also true for a predefined SQL string. If you need to build the string before executing it then VBA would make a lot more sense.

I'm never going to recommend use of macros as I believe that is a shortcut to a dead-end and any time learning how to use them is essentially wasted time, but that isn't the answer to this particular question.
Nov 23 '11 #2
colintis
255 100+
If you are running the query in Access, simply correct Date()-1 into DateDiff("d",1,Date).
Nov 23 '11 #3
NeoPa
32,556 Expert Mod 16PB
That change may be more aesthetically pleasing for a coder but would have no effect on the running of the query I'm afraid (Of course you'd need to fix the fix as it provides tomorrow's date instead of yesterday's, but that's a minor point).
Nov 23 '11 #4
suet
9
Hmm..I just realize the sql codes did not really explain what I am trying to do.
I need to figure out if I can update "vendor chanage" and "vendor change date" based on one condition and "mod code change" and "mod code change date" with another condition within the same table. All 4 fields are in the same table. With other programming language, I can easily use case statement and code the criteria to apply the update value. Can I do this without VBA code? The query will run with querydef, without building a string. Hope this is littel clear.
Nov 23 '11 #5
NeoPa
32,556 Expert Mod 16PB
You can do that (and No - You didn't ask that remotely clearly in post #1). Even now you provide little in the way of detail, but I'll try to explain in more general terms for you.

IIf() can be used in this scenario, but not to update or not (It cannot control the process - it simply returns values). What you can do though is to update a field to its existing value if you don't want it updated, but a separate (new) value if you do.

Here's an example that should be self-explanatory :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Table1]
  2. SET    [Surname] = IIf([Married],[SpouseName],[Surname])
Nov 24 '11 #6
suet
9
I applied IIF to my update query which works perfectly!
Thanks a bunch!
Nov 24 '11 #7
NeoPa
32,556 Expert Mod 16PB
Good to hear it. Not everybody gets that - so well done.
Nov 24 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Duane Phillips | last post by:
"David Portas" <snipped for brevity> wrote: Example 1: > > UPDATE table_a > SET col = ? /* Unspecified */ > WHERE EXISTS > (SELECT * > FROM table_b > WHERE table_b.key_col =...
2
by: Fons Roelandt | last post by:
Heelo, I have to Update all fields from a table with the values of a related table, i've tried some querys i found on the internet, but nothing seems to word, i even tried to lookup the value...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
1
by: odie123 | last post by:
Hi Anybody to assist with a problem. I have A products db with the following fields. Description and Cost. The 2nd db closing stock. I want to use db products in db closing stock using the products...
11
by: tara99 | last post by:
Can some one tell me the correct syntax of Update statment for updating multiple fields. I want to update few item in record (few fields i a table). Thanks
1
by: Brad Isaacs | last post by:
Using ASP.NET 2.0 with SQL Server 2000 Inside my dropdown list box I am using an SQL DataSource to select the following data SELECT RTRIM(c.Name_First) + ' ' + RTRIM(c.Name_Last) AS Contact,...
3
by: dirk | last post by:
Hi, Being new coding in phpI have a question concerning server side form validation. In a php script I check if a form is correctly filled in. Now I want that the page containing the forms...
3
by: linwork | last post by:
Hi, I have a form that updates an issue log. Among the other fields on it, it contains a combobox with 2 columns that I would like to update 2 separate fields in my database. ComboErrorDesc...
2
by: noriko | last post by:
Hello, I have a table with 4 fields. I want to insert value into one of the fields, based on If condition of other fields... Company1, Company2, Company3, NoOfCompanies xxx,,, xxx,xxx,,...
1
by: ajyoti | last post by:
hiii i am trying to update a table named "ordertab" through a vb6.0 form this table already consists of some data,means some fields have data Now i want to fill the data in other fields also,for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.