Go Back   DeveloperBarn Forums > Databases > SQL Development

Sponsored Links

Discuss "Return Default Date If Null" in the SQL Development forum.

SQL Development - Structured Query Language (SQL) is the talk of databases. Discuss topics such as joins, triggers and other advanced SQL topics.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old June 6th, 2008, 11:26 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 815
Thanks: 19
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default Return Default Date If Null

I have a query like the following:

Code:
"SELECT " & _
    [last_name]," & _
    [first_name]," & _
    [hire_date]," & _
"FROM vw_people " & _
"WHERE id = @id"
Now, the people that designed the database have NULL values EVERYWHERE! It's a complete mess that I have to deal with. For some ungodly reason, someone's hire date is NULL. I know, makes no sense. Why would this person have a record if they don't work for us and don't have a hire date?

Anyway, is there a way via my above query to return a default date if "hire_date" is NULL? I'm using SQL Server 2000. This is a hard coded query unfortunately and I'm not sure if I can do some sort of SELECT CASE here.
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
Sponsored Links
  #2  
Old June 6th, 2008, 11:29 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

try something like this
Code:
"SELECT " & _
    [last_name]," & _
    [first_name]," & _
    CASE WHEN [hire_date] IS NULL THEN 'default_date' ELSE [hire_date] END AS hire_date," & _
"FROM vw_people " & _
"WHERE id = @id"
sorry ... my bad ... didn't read that it's a hard coded query. what is it being used in?
__________________
Quote of the Month:
Regret: It hurts to admit when you make mistakes - but when they're big enough, the pain only lasts a second.

Questions to Ponder:
Could it be that all those trick-or-treaters wearing sheets aren’t going as ghosts but as mattresses?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
Reply With Quote
  #3  
Old June 6th, 2008, 11:34 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 815
Thanks: 19
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

This is a VB.Net application using SQL Server 2000.
Reply With Quote
  #4  
Old June 6th, 2008, 11:36 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

then you would need to do something in the .NET app to account for NULL values?
Reply With Quote
  #5  
Old June 6th, 2008, 11:39 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 815
Thanks: 19
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

That's the problem. For some reason certain .Net methods won't accept NULL dates. Which is why I'm trying to return a default value before it gets to the method.
Reply With Quote
  #6  
Old June 6th, 2008, 11:42 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

then without changing the query ... i don't see how you can. unless you update the database and put a default value in there.
Reply With Quote
  #7  
Old June 6th, 2008, 11:44 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 815
Thanks: 19
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by mehere View Post
then without changing the query ... i don't see how you can. unless you update the database and put a default value in there.
What do you mean 'without changing the query'? I want to change the query if I can get it to return the default date

And believe me, I'd much rather rid myself of NULL in this database, but that is not up to me, unfortunately.
Reply With Quote
  #8  
Old June 6th, 2008, 11:46 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

ugh ... you said it was hardcoded ... wow ... need to get my head out of the clouds. use what i posted then.
Reply With Quote
  #9  
Old June 6th, 2008, 11:48 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 815
Thanks: 19
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by mehere View Post
ugh ... you said it was hardcoded ... wow ... need to get my head out of the clouds. use what i posted then.
lol it is hard coded. I was asking if there was a way without TSQL to do this.

When you said 'change your query', I was confused as that was a vague statement.

So I'm assuming there is no way to do what I want and I'm going to have to put my right boot on when I go talk to the database morons.
Reply With Quote
  #10  
Old June 6th, 2008, 01:07 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Hmm, y'all seem to be posting in circles here JMH & mehere . Obviously sumpin' gotta change sumplace, so which would you like to do:
(a) Change the data
(b) Change the query
(c) Handle the null in code
(d) Write a sproc
(e) Kill the DB designer
?
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > SQL Development

Bookmarks

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
No Default Member Found for type richyrich .Net Development 5 May 29th, 2008 01:33 PM
Webform Default Button Devwhiz .Net Development 9 May 15th, 2008 01:15 PM


All times are GMT -4. The time now is 12:43 PM.



Content Relevant URLs by vBSEO 3.2.0