Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select one value as another

Status
Not open for further replies.

LinuxKommy

Technical User
Apr 2, 2002
31
US
How would i select one value based on another? the table stores its value as "Y" or "N", but i want 1 or 0. if they were numbers, i could perform the operation much more easily.
if anyone can suggest a better way to do this operation, i'd love to hear it because i'm running out of ideas here.

the table stores the flag field and a quantity of items. An example would be:

Flag Stock# Qty
---- ------ ---
Y 560000 2
Y 570000 1
Y 580000 1

I want it to return 4. the grouping occurs on an orderno, and the where clause selects all rows with the flag set to "Y". but i need it to count the quantity in there too? how would i do that?
 
Since you say you're grouping on ORDERNO, I think it's as simple as

Select Orderno, sum(Qty)
From Table
Where flag = 'Y'
Group by orderno


But the fact you want Y to be 1 and N to be zero is kind of confusing
 
thanks....i feel really stupid now...actually i was coming back to write a reply like that. It had just occurred to me!

i wanted Y=1 so that i could do sum(Flag*qty), but then i realized that i would select the "Y"'s only anyway.

thanks for your help, and please don't laugh :)
 
No problem, we've all been there. Although some people won't admit it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top