SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Changing Null Values to Blanks
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 08/15/2013 :  04:19:01  Show Profile  Reply with Quote
Hey guys
Hope your well

Aim- the following columns “Cancel_Date”, “First_Post_Date”,“Last_Post_Date” can either be populated with figures or have a null value.
I want all Null values to be removed and be replaced with a blank
Final table is

Select *
from #test
left join #SF_AccountBuild on #test.FDMSAccountNo = #SF_AccountBuild.[External FDMSaccountno]

Results

[FDMSAccountNo],
External_ID ,
Parentsfid,
[DBA Name],
[Legal Name],
Street,
[MM3-DBA-ADDR2],
[MM3-DBA-ADDR4],
City,
County,
Postalcode,
Country,
Phone,
Open_Date,
Cancel_Date,
First_Post_Date,
Last_Post_Date,
Account_Id,
External Fdmsaccountno,
[External FDMSaccountno]

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 08/15/2013 :  06:22:50  Show Profile  Reply with Quote
COALESCE(First_Post_Date,' ') AS First_Post_Date, etc








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 08/15/2013 :  06:36:16  Show Profile  Visit SwePeso's Homepage  Reply with Quote
That will set the column to 1900-01-01 if the column is DATE, DATETIME, SMALLDATETIME, DATETIME2 OR DATETIMEOFFSET.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 08/15/2013 :  06:51:43  Show Profile  Reply with Quote
DonAtWork

Thank you very much :)
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 08/16/2013 :  07:56:17  Show Profile  Reply with Quote
Peter is correct tho, it will return the 1900-01-01 if you actually use a date type column.

COALESCE(CAST(First_Post_Date AS VARCHAR),' ') AS First_Post_Date, etc

Should work if you have actual datetime columns...

HOWEVER... you now have a string instead of a nice datetime type to work with...
perhaps change the data in your front end application instead?

Thanks for the heads up Peter!








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 08/18/2013 :  11:41:29  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by SwePeso

That will set the column to 1900-01-01 if the column is DATE, DATETIME, SMALLDATETIME, DATETIME2 OR DATETIMEOFFSET.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA


Note only to date and time related datatypes, the default value may affect to other datatypes as well. http://beyondrelational.com/modules/2/blogs/70/posts/10841/empty-string-and-default-values.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000