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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to combine the NULL value with some values dur
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

partap26
Starting Member

India
27 Posts

Posted - 05/28/2013 :  05:24:18  Show Profile  Reply with Quote
SELECT cast(a.po_date As Date) as podate, cast(a.supply_date As Date) as sddate,
CASE WHEN supply_date IS NULL
THEN '00/00/0000'
END
FROM device_order a
INNER JOIN customer_details b ON a.customer_name = b.customer_name

The output is
po_date | No column name | sdate

2013-05-14 | 2013-05-23 | NULL
2013-05-17 | NULL | 00/00/0000
2013-05-17 | NULL | 00/00/0000
2013-05-14 | NULL | 00/00/0000

But i want

po_date | sdate

2013-05-14 | 2013-05-23
2013-05-17 | 00/00/0000
2013-05-17 | 00/00/0000
2013-05-14 | 00/00/0000

How to do this?????

senthil_nagore
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 05/28/2013 :  05:28:06  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
Note : Assuming supply_date is varchar column

SELECT cast(a.po_date As Date) as podate, CASE WHEN supply_date IS NULL
THEN '00/00/0000' else supply_date
END as sdate
FROM device_order a
INNER JOIN customer_details b ON a.customer_name = b.customer_name




Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008

Edited by - senthil_nagore on 05/28/2013 05:28:45
Go to Top of Page

partap26
Starting Member

India
27 Posts

Posted - 05/28/2013 :  05:30:47  Show Profile  Reply with Quote
Conversion failed when converting date and/or time from character string for this query
Go to Top of Page

partap26
Starting Member

India
27 Posts

Posted - 05/28/2013 :  05:33:34  Show Profile  Reply with Quote
NO assumption please.. supply_date , po_date are date columns
Go to Top of Page

senthil_nagore
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 05/28/2013 :  05:37:24  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
hope this will work

SELECT cast(a.po_date As Date) as podate, CASE WHEN supply_date IS NULL
THEN '00/00/0000' else cast(supply_date as varchar(50))
END as sdate
FROM device_order a
INNER JOIN customer_details b ON a.customer_name = b.customer_name



Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

partap26
Starting Member

India
27 Posts

Posted - 05/28/2013 :  05:44:56  Show Profile  Reply with Quote
This is 100% accurate
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/28/2013 :  05:56:25  Show Profile  Reply with Quote
why not this?


SELECT cast(a.po_date As Date) as podate, COALESCE(supply_date,'0000-00-00') as sdate
FROM device_order a 
INNER JOIN customer_details b ON a.customer_name = b.customer_name


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.1 seconds. Powered By: Snitz Forums 2000