Solved

is null two queries

Posted on 2011-03-11
8
212 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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 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 41

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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 SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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