dbTalk Databases Forums  

Assign value based on value field in query

comp.databases.ms-access comp.databases.ms-access


Discuss Assign value based on value field in query in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas Andersson
 
Posts: n/a

Default Assign value based on value field in query - 08-13-2010 , 05:20 PM






I'm making a query where I want to create a new column with a value based on
another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA, RES, KIA).
the new coumn should check this and assign a value of 1 for RTB and 0,5 for
all others.
How would I do this?

Reply With Quote
  #2  
Old   
Thomas Andersson
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 05:54 PM






Thomas Andersson wrote:

Quote:
I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA, RES,
KIA). the new coumn should check this and assign a value of 1 for RTB
and 0,5 for all others.
How would I do this?
I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")

Reply With Quote
  #3  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 05:56 PM



What error?

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele/AccessIndex.html
Co-author: "Access 2010 Solutions", published by Wiley
(no private e-mails, please)


"Thomas Andersson" <thomas (AT) tifozi (DOT) net> wrote

Quote:
Thomas Andersson wrote:

I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA, RES,
KIA). the new coumn should check this and assign a value of 1 for RTB
and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")


Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 05:59 PM



Thomas Andersson wrote:

Quote:
I'm making a query where I want to create a new column with a value based on
another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA, RES, KIA).
the new coumn should check this and assign a value of 1 for RTB and 0,5 for
all others.
How would I do this?


In the query builder enter the column name, a colon, then expression.
Ex: [A] is Acronym

NumVal : IIF([A]="RTB",1,IIF([A]="MIA",0,5))

Whats the diff between 0 and 5 values?

Reply With Quote
  #5  
Old   
Thomas Andersson
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 06:06 PM



Douglas J. Steele wrote:

Invalid Syntax, missing operand, non quoted text or invalid char/comma.

Quote:
What error?

I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA,
RES, KIA). the new coumn should check this and assign a value of 1
for RTB and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")

Reply With Quote
  #6  
Old   
Thomas Andersson
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 06:11 PM



Salad wrote:
Quote:
Thomas Andersson wrote:

I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA,
RES, KIA). the new coumn should check this and assign a value of 1
for RTB and 0,5 for all others.
How would I do this?


In the query builder enter the column name, a colon, then expression.
Ex: [A] is Acronym

NumVal : IIF([A]="RTB",1,IIF([A]="MIA",0,5))

Whats the diff between 0 and 5 values?
If they RTB (Return to Base) they get full credit for their mission,
otherwise they only get half. (the second choise is 0,5 (half), not 0 and 5
BTW). T&hat solutions is the same I'm trying except you nested yours.
Hmm, since I'm gonna use an additional query to count all the credits up
maybe I should set it to 2 and 1 instead and then just half the total in the
second query?

Reply With Quote
  #7  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 08:09 PM



"Thomas Andersson" <thomas (AT) tifozi (DOT) net> wrote

Quote:
Thomas Andersson wrote:

I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA, RES,
KIA). the new coumn should check this and assign a value of 1 for RTB
and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")
Try using a period as a decimal point instead of a comma:

IIf([Sortie].[Result] = "RTB", "1", "0.5")

Reply With Quote
  #8  
Old   
Thomas Andersson
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 08:32 PM



Stuart McCall wrote:

Quote:
I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA,
RES, KIA). the new coumn should check this and assign a value of 1
for RTB and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")

Try using a period as a decimal point instead of a comma:

IIf([Sortie].[Result] = "RTB", "1", "0.5")
Doubt it will help as I tried using 2 and 1 as values and get the same
error.
This is a headscratcher as according to all examples I've found this SHOULD
be correct.
Theer are no extra commas, all text and numbers are enclosed in quotes and
the only operand is = which is legal.. so WHAT is Access complaining about??

Reply With Quote
  #9  
Old   
Salad
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-13-2010 , 09:10 PM



Thomas Andersson wrote:

Quote:
Stuart McCall wrote:


I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA,
RES, KIA). the new coumn should check this and assign a value of 1
for RTB and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")

Try using a period as a decimal point instead of a comma:

IIf([Sortie].[Result] = "RTB", "1", "0.5")


Doubt it will help as I tried using 2 and 1 as values and get the same
error.
This is a headscratcher as according to all examples I've found this SHOULD
be correct.
Theer are no extra commas, all text and numbers are enclosed in quotes and
the only operand is = which is legal.. so WHAT is Access complaining about??


Throwing mud at wall, try [Sortie]![Result]. Then try simply [Result].
Then verify there really is a Result field and it is not misspelled.
Then try 1 and 2 without quotes. Then pull out .44 magnum and snear at
screen and say "Do you feel lucky, punk? Well do you?"

Reply With Quote
  #10  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: Assign value based on value field in query - 08-14-2010 , 11:56 AM



So what's the SQL for the entire query?

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/djsteele
Co-author: "Access 2010 Solutions", published by Wiley
(no e-mails, please!)



"Thomas Andersson" <thomas (AT) tifozi (DOT) net> wrote

Quote:
Douglas J. Steele wrote:

Invalid Syntax, missing operand, non quoted text or invalid char/comma.

What error?

I'm making a query where I want to create a new column with a value
based on another columns content
The source will contain either of 4 3-letter acronyms (RTB, MIA,
RES, KIA). the new coumn should check this and assign a value of 1
for RTB and 0,5 for all others.
How would I do this?

I thought bthis would do it but keep getting errors
IIf([Sortie].[Result] = "RTB", "1", "0,5")


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.