If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > default value in query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-04, 12:28
jvargas jvargas is offline
Registered User
 
Join Date: Nov 2003
Posts: 6
Thumbs up default value in query

Is there a way to for a query to return a default value (specified in the query) if a request value is NULL?

In my case I am returning an average wage for each employee record but people without wages should return some sort of default amount rather than just blank/null.

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-27-04, 13:18
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
SELECT employee, AVG(COALESCE(wagefield, 0))
FROM emptable
WHERE ...

"0" in this example is the default value.
Reply With Quote
  #3 (permalink)  
Old 02-27-04, 18:06
jvargas jvargas is offline
Registered User
 
Join Date: Nov 2003
Posts: 6
Talking

Awesome, thanks for the help. It worked perfect.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On