Fix SQL statement, returning error ...

helpangel

Registered User.
Local time
Today, 15:00
Joined
Oct 10, 2007
Messages
44
Hello,
Run-time error ...
No value given one or more required paramete

Code:
UPDATE GuitarOptionDetails SET GuitarOptionDetails.OptionCombo = Concatenate("SELECT Option_Item FROM GuitarHeader WHERE GuitarItem & Option_Item =""" & [GuitarOptionDetails].[GuitarItem] & [GuitarOptionDetails].[Option_Item] & """");

basically i need to create an update query to update the OptionCombo field where:
1. OptionCategory=BODY
2. Combine all the BODY OptionItems as one into the OptionCombo field (the Concatenate() function should accomplish this portion)
3. For each InvoiceNumber AND GuitarItem.

NOTE: some invoices will not have any BODY Option_Item, this can place "N" in the OptionCombo BUT only if the invoice does not have a single BODY Option_Item, if it does, it needs to put the combined BODY Option_Item values into the OptionCombo field.

How should I rewrite the SQL to achieve this without getting this error?
 
Run-time error ...
No value given one or more required parameters
Code:
UPDATE GuitarOptionDetails SET 
GuitarOptionDetails.OptionCombo = Concatenate("SELECT Option_Item 
FROM GuitarHeader WHERE GuitarItem & Option_Item =
""" & [GuitarOptionDetails].[GuitarItem] & [GuitarOptionDetails].[Option_Item] & """");
The code just doesn't look right...
No value given?? Well, I would say that's right then.... :rolleyes:
basically i need to create an update query to update the OptionCombo field where:
1. OptionCategory=BODY
2. Combine all the BODY OptionItems as one into the OptionCombo field (the Concatenate() function should accomplish this portion)
3. For each InvoiceNumber AND GuitarItem.
How should I rewrite the SQL to achieve this without getting this error?
Well, the following will take care of number 1...
Code:
UPDATE GuitarOptionDetails SET 
GuitarOptionDetails.OptionCombo = [color=red]"I don't understand this part (as it relates to Number 2)"[/color]
WHERE OptionCategory = "BODY"
As far as #2...combine Option Items?? So where are they?? Structuring?? In other fields?? How many other fields?? Does it vary?? Is there another condition involved here?? It sounds like some of those fields might be empty. If they are, does that come into play?? It won't if they are NULL, but are they??
 
so when it updates it would have the following results in the OptionCombo field as such:
Code:
InvoiceDate	InvoiceNumber	GuitarItem	Option_Item	OptionCategory	OptionCombo
9/7/07	2365186	AE185	38	Body	38 BB
9/7/07	2365186	AE185	AB	Neck	38 BB
9/7/07	2365186	AE185	ABL	Options	38 BB
9/7/07	2365186	AE185	BB	Body	38 BB
9/7/07	2365186	AE185	DTS	Finishes	38 BB
9/7/07	2365186	AE185	G	Options	38 BB
9/7/07	2365186	AE185	QPH	Headstock	38 BB
9/7/07	2365186	AE185	QSSA	Finishes	38 BB
9/7/07	2365186	AE185	STF	Neck	38 BB
9/7/07	2365186	AE185	TN	Neck	38 BB
9/7/07	2365203	AE185	38	Body	38
9/7/07	2365203	AE185	CTH	Headstock	38
9/7/07	2365203	AE185	FPH	Headstock	38
9/7/07	2365203	AE185	FSKA	Finishes	38
9/7/07	2365203	AE185	NIN	Neck	38
9/7/07	2365203	AE185	SL	Options	38
9/6/07	2364987	AE185	BC	Options	N
9/6/07	2364987	AE185	FPH	Headstock	N
9/6/07	2364987	AE185	FTCA	Finishes	N
 
Ok, so based on your table, and what you said in number two, I guess this is what you want...
Code:
UPDATE GuitarOptionDetails SET GuitarOptionDetails.OptionCombo = 
[color=red]([Guitar Item] & ", " & [Option Item]) AS [New Field Name][/color]
WHERE OptionCategory = "BODY"
This creates a new field that "Concats" the two above field values together for every record (spaced by the "," delimiter). I'm not sure if your asking how to concat different fields in a record, or weather you are wanting to Concat all the values of a field into one record (You can't do this with CONCAT).
 
thanks for the attempt.

no, not combine GuitarItem and Option_Item.
but combine all of the Option_Items when it's OptionCategory = Body

don't worry, i have a Concatenate() the SQL will be written in. i just need to get the SQL statement to be correct. :-)
 
i thought this:
Code:
IIf([OptionCategory]="Body",Concatenate("SELECT OptionCombo FROM GuitarOptionDetails WHERE GuitarItem & Option_Item =""" & [GuitarOptionDetails].[GuitarItem] & [GuitarOptionDetails].[Option_Item] & """"),"N")

but still needs some more tuning ...

thoughts?
 
I'm using:

IIf([OptionCategory]="Body",Concatenate("SELECT Option_Item FROM GuitarOptionDetails WHERE GuitarItem & Option_Item =""" & GuitarOptionDetails.GuitarItem & GuitarOptionDetails.Option_Item & """"),"N")

and the result is this:
Code:
InvoiceDate	InvoiceNumber	GuitarItem	Option_Item	OptionCategory	OptionCombo
10/18/07	2372490	CT3M	B	Finishes	N
10/18/07	2372490	CT3M	BC	Options	N
10/18/07	2372559	AE185	38	Body	N
10/18/07	2372559	AE185	BC	Options	N
10/18/07	2372559	AE185	DTS	Finishes	N
10/18/07	2372559	AE185	GL	Options	N
10/18/07	2372559	AE185	IN	Headstock	N
10/18/07	2372559	AE185	NIN	Neck	N
10/18/07	2372559	AE185	QPH	Headstock	N
10/18/07	2372559	AE185	QSKA	Finishes	N
10/18/07	2372559	AE185	R14	Neck	N
10/18/07	2372559	AE185	SL	Options	N
10/18/07	2372559	AE185	STJF	Neck	N
10/18/07	2372559	AE185	TN	Neck	N
10/15/07	2371872	LB76P	5M	Neck	SP2P
10/15/07	2371872	LB76P	BC	Options	SP2P
10/15/07	2371872	LB76P	BMF	Neck	SP2P
10/15/07	2371872	LB76P	KOA	Woods	SP2P
10/15/07	2371872	LB76P	SP2P	Body	SP2P
10/15/07	2371884	B4	BST	Finishes	HB2 HB2
10/15/07	2371884	B4	HB2	Body	HB2 HB2
10/11/07	2371330	SC90M	5W	Neck	RB RB RB
10/11/07	2371330	SC90M	5W	Body	RB RB RB
10/11/07	2371330	SC90M	B	Finishes	RB RB RB
10/11/07	2371330	SC90M	BC	Options	RB RB RB
10/11/07	2371330	SC90M	CG	Finishes	RB RB RB
10/11/07	2371330	SC90M	NIN	Neck	RB RB RB
10/11/07	2371330	SC90M	RB	Body	RB RB RB

so in these 2 invoices the 1st one is correct, "N" because there's no Body optioncategory.
But for the 2nd invoice "2372559" there is one Body option_item "38". It should have put "38" in the OptionCombo field instead put "N".
And still the 3rd invoice has "SP2P" in OptionCombo, which is correct since that's the ONLY Body option_item for this invoice.
And still the 4th invoice why it has "HB2 HB2" instead of just "HB2"?
And the last one shown here, why does it only have "RB RB RB" instead of "5W RB"?

what's wrong with my SQL?
 
Help_Angel, I have marked up your pasted table to better read it...
Code:
InvoiceDate[color=red](1)[/color]	InvoiceNumber[color=red](2)[/color] GuitarItem[color=red](3)[/color]	Option_Item[color=red](4)[/color]	OptionCategory[color=red](5)[/color]	OptionCombo[color=red](6)[/color]
10/18/07[color=red](1)[/color] 2372490[color=red](2)[/color] CT3M[color=red](3)[/color] B[color=red](4)[/color]	Finishes[color=red](5)[/color]	N[color=red](6)[/color]
10/18/07	2372490	CT3M	BC	Options	N
10/18/07	2372559	AE185	38	Body	N
10/18/07	2372559	AE185	BC	Options	N
10/18/07	2372559	AE185	DTS	Finishes	N
10/18/07	2372559	AE185	GL	Options	N
10/18/07	2372559	AE185	IN	Headstock	N
10/18/07	2372559	AE185	NIN	Neck	N
10/18/07	2372559	AE185	QPH	Headstock	N
10/18/07	2372559	AE185	QSKA	Finishes	N
10/18/07	2372559	AE185	R14	Neck	N
10/18/07	2372559	AE185	SL	Options	N
10/18/07	2372559	AE185	STJF	Neck	N
10/18/07	2372559	AE185	TN	Neck	N
10/15/07[color=red](1)[/color]	2371872[color=red](2)[/color]	LB76P[color=red](3)[/color] 5M[color=red](4)[/color]	Neck[color=red](5)[/color]	SP2P[color=red](6)[/color]
10/15/07	2371872	LB76P	BC	Options	SP2P
10/15/07	2371872	LB76P	BMF	Neck	SP2P
10/15/07	2371872	LB76P	KOA	Woods	SP2P
10/15/07	2371872	LB76P	SP2P	Body	SP2P
10/15/07	2371884	B4	BST	Finishes	HB2 HB2
10/15/07	2371884	B4	HB2	Body	HB2 HB2
10/11/07	2371330	SC90M	5W	Neck	RB RB RB
10/11/07	2371330	SC90M	5W	Body	RB RB RB
10/11/07	2371330	SC90M	B	Finishes	RB RB RB
10/11/07	2371330	SC90M	BC	Options	RB RB RB
10/11/07	2371330	SC90M	CG	Finishes	RB RB RB
10/11/07	2371330	SC90M	NIN	Neck	RB RB RB
10/11/07	2371330	SC90M	RB	Body	RB RB RB
As you can see from the table, your CONCAT statement in the IIF function is not being evaluated. I don't think you are writing the correct code for what you want really. This statement of yours...
basically i need to create an update query to update the OptionCombo field where:
1. OptionCategory=BODY
2. Combine all the BODY OptionItems as one into the OptionCombo field (the Concatenate() function should accomplish this portion)
suggests that there is (or should be) more than one value in certain RECORDS under the "OptionItem" field. However, in your table, I only see ONE value per record in this field. Also, this statement from you in red...
But for the 2nd invoice "2372559" there is one Body option_item "38". It should have put "38" in the OptionCombo field instead put "N".
And still the 3rd invoice has "SP2P" in OptionCombo, which is correct since that's the ONLY Body option_item for this invoice.
And still the 4th invoice why it has "HB2 HB2" instead of just "HB2"?
suggests that for this particular record, the value of the cell in the "OptionCombo" is "HB2 HB2" (even before the IIF function is performed). I don't think it is, but that's what it looks like.

I'm not sure about the irratic nature of the data output; it certainly does not appear to make much sense. I can tell you these facts though...

** The CONCAT function IS valid, because if it wasn't, you wouldn't be able to view your query.
** If you are simply trying to CONCAT the values from the "OptionItem" field and the "OptionCombo" field, you don't need to write an essay....
[OptionItem] & " " & [OptionCombo] works just fine. :)

** When you write a function (DSum, IIF, etc...) or expression (field + field), Access produces a temporary field to store this data, and also assignes it a temporary name if you haven't. This is NOT the same as simply selecting the prepopulated fields from a table.

Another possibility for you to consider...
If you have selected all your tables in the field, PLUS included your IIF function as another temporary field in the query, I am guessing that some sort of duplication is happening, and may be jumbling up your data (but this is just a guess). "IIF([field] = "whatever", CONCAT(field1 & field2), "N")" Say you write that IIF function, and you also include "field1" & "field2" as separate columns in your SELECT statement....

Makes me wonder if this will duplicate actions on "field1" from the IIF statement....?? :confused: :confused:
 
Last edited:
I have just looked at your database from the last thread you posted about it. Craig was helping you on it, and although I did not read through the million or so posts that are in the thread, I did look through the file. Apparently, there is more going on here than what you originally had given information for.

There are obviously going to be JOINS involved with this, so I'm not really convinced that it is as simple as you think. From reading the last post in the other thread, it doesn't seem as though that problem was ever solved. Was it??
 
Hi ajetrumpet,
yes, but for a different approach. it's been a difficult task and i've come up with another direction and needed help with the SQL statement using a new field OptionCombo.

basically trying to now get ONLY the Body Option_items concatenated into the new field OptionCombo and if there are no BODY Option_item then to put the value N.
 
basically trying to now get ONLY the Body Option_items concatenated into the new field OptionCombo and if there are no BODY Option_item then to put the value N.
Then...
Code:
IIF ([option_item] = NULL, "N", ([option_item] & " " & [OptionCombo]))
AS [Temporary OptionCombo Field]
should work just fine.
 
Hi!
thanks ... but,
doesn't ([option_item] & " " & [OptionCombo]) mean combine option_item optioncombo?

there's nothing in OptionCombo field. i need it to run the update query to update the OptionCombo field with just the data from Option_Items ONLY when the Option_Items are Body from OptionCategory, otherwise place a N into the OptionCombo.
 
Then...
Code:
IIF ([option_item] = NULL, "N", ([option_item] & " " & [OptionCombo]))
AS [Temporary OptionCombo Field]
should work just fine.

Nothing is ever equal to Null, so you can not test for it that way (try it). You can either use IsNull within the IIf or Nz() may often be simpler.
 
Well thank you Paul...

I was sure having a bad day, wasn't I??

You got me twice, congratulations =)

I guess we'll just have to replace the "=" sign then....
Code:
IIF ([option_item] =[color=red] <---put "[B]IS[/b]" here instead of "[b]=[/b]" !!! [/color]NULL,
 "N", ([option_item] & " " & [OptionCombo]))
AS [Temporary OptionCombo Field]
 
Last edited:
Hi!
thanks ... but,
doesn't ([option_item] & " " & [OptionCombo]) mean combine option_item optioncombo?
YES, it does, but apparently that is not what you are looking for. That's OK....
i need it to run the update query to update the OptionCombo field with just the data from Option_Items ONLY when the Option_Items are Body from OptionCategory, otherwise place a N into the OptionCombo.
Now, THAT is a clearly stated question!! :) If you're just updating, I think you'll have to do it twice...one for updating the NULLS and one for updating the other condition. For the "value" condition...
Code:
UPDATE table SET Table.OptionCombo = Table.OptionCategory
WHERE OptionCategory = "Body";

If you're looking to use the IIF statment, just remember that it is only a temporary field in a query. To make it permanent in the table, you will have to make another table and join the columns from both.
 
hi!
thank you. i will once I get a chance.

we have to pack and be ready to evacuate Poway, CA

the fires have gotten worse due to the strong winds and it's close. they have evacuated Rancho Bernardo which is just our neighboring city.
 

Users who are viewing this thread

Back
Top Bottom