Solved

is null two queries

Posted on 2011-03-11
8
197 Views
Last Modified: 2012-06-27
(select max(isnull(dateentered,0)) from payments where orderid=o.orderid) as paymentdate


instead of 0

I want to use
select dateordered from orders where orderid=o.orderid
0
Comment
Question by:rgb192
8 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 35110321
(select max(isnull(dateentered,(select dateordered from orders where orderid=o.orderid))) from payments where orderid=o.orderid) as paymentdate
0
 

Author Comment

by:rgb192
ID: 35110441
(select max(isnull(dateentered,(select dateordered from orders where orderid=70194))) from payments where orderid=70194) as paymentdate


Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'as'.
0
 
LVL 39

Expert Comment

by:lcohan
ID: 35111122
select max(isnull(dateentered,(select dateordered from orders where orderid=70194))) from payments where orderid=70194 as paymentdate
0
 
LVL 39

Expert Comment

by:lcohan
ID: 35111133
Darn...copy/paste...


select max(isnull(dateentered,(select dateordered from orders where orderid=70194))) from payments where orderid=70194
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:rgb192
ID: 35111429

select max(isnull(dateentered,(select dateordered from orders where orderid=70194))) from payments where orderid=70194

Msg 130, Level 15, State 1, Line 1
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.


I think you copy paste the same query
minus the as paymentdate

but I need the 'as paymentdate'



0
 
LVL 39

Assisted Solution

by:lcohan
lcohan earned 150 total points
ID: 35111777
select top 1
      case when p.dateentered is null then (select dateordered from orders o where o.orderid=p.orderid)
      else p.dateentered end as paymentdate
from payments p
order by 1 desc
0
 
LVL 40

Accepted Solution

by:
Sharath earned 350 total points
ID: 35112187
try this.
SELECT ISNULL((SELECT MAX(dateentered) 
                 FROM payments 
                WHERE orderid = o.orderid),(SELECT TOP 1 dateordered 
                                              FROM orders 
                                             WHERE orderid = o.orderid)) AS paymentdate

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35112576
thanks
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now