Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

is null two queries

Posted on 2011-03-11
8
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 40

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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 40

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
 

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 40

Assisted Solution

by:lcohan
lcohan earned 600 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 41

Accepted Solution

by:
Sharath earned 1400 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 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