Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to combine the NULL value with some values dur

Author  Topic 

partap26
Starting Member

27 Posts

Posted - 2013-05-28 : 05:24:18
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
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2013-05-28 : 05:28:06
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
Go to Top of Page

partap26
Starting Member

27 Posts

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

partap26
Starting Member

27 Posts

Posted - 2013-05-28 : 05:33:34
NO assumption please.. supply_date , po_date are date columns
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2013-05-28 : 05:37:24
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

27 Posts

Posted - 2013-05-28 : 05:44:56
This is 100% accurate
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-28 : 05:56:25
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
   

- Advertisement -