[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Sort a Union Query

Posted on 2008-06-19
3
Medium Priority
?
251 Views
Last Modified: 2010-03-20
How can I sort the query below by dtmcontact desc.  Thanks
create procedure spPANotes          
(                                  
 @paramid varchar(15)                                  
                                 
)            
as          
          
          
(SELECT dtmcontact as date,tblPAVisit.lngPatientID, tblPAVisit.lngVisitID, tblPAMfg.strDenied AS 'memo', 'Mfg Notes' as notetype           
FROM tblPAVisit INNER JOIN tblPAMfg ON tblPAVisit.lngVisitID = tblPAMfg.lngVisitID           
WHERE (tblPAVisit.lngPatientID = @paramid) AND (tblPAMfg.strDenied IS NOT NULL)          
UNION ALL          
SELECT dtmcontact as date,tblPAVisit.lngPatientID , tblPAVisit.lngVisitID, tblPADiabetic.memVoucher AS 'memo' , 'Diabetic Notes'as notetype         
FROM tblPAVisit INNER JOIN tblPADiabetic ON tblPAVisit.lngVisitID = tblPADiabetic.lngVisitID           
WHERE (tblPAVisit.lngPatientID = @Paramid)         
UNION ALL          
SELECT dtmcontact as date, tblPAVisit.lngPatientID , tblPAVisit.lngVisitID, tblPAVoucher.memVoucher AS 'memo'  , 'Voucher Notes'as notetype         
FROM tblPAVoucher INNER JOIN tblPAVisit ON tblPAVoucher.lngVisitID = tblPAVisit.lngVisitID           
WHERE (tblPAVisit.lngPatientID = @Paramid) AND (tblPAVoucher.memVoucher IS NOT NULL)  )

Open in new window

0
Comment
Question by:running32
[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
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 21825074
create procedure spPANotes          
(                                  
 @paramid varchar(15)                                  
                                 
)            
as          
         
         
SELECT dtmcontact as date,tblPAVisit.lngPatientID, tblPAVisit.lngVisitID, tblPAMfg.strDenied AS 'memo', 'Mfg Notes' as notetype          
FROM tblPAVisit INNER JOIN tblPAMfg ON tblPAVisit.lngVisitID = tblPAMfg.lngVisitID          
WHERE (tblPAVisit.lngPatientID = @paramid) AND (tblPAMfg.strDenied IS NOT NULL)          
UNION ALL          
SELECT dtmcontact as date,tblPAVisit.lngPatientID , tblPAVisit.lngVisitID, tblPADiabetic.memVoucher AS 'memo' , 'Diabetic Notes'as notetype        
FROM tblPAVisit INNER JOIN tblPADiabetic ON tblPAVisit.lngVisitID = tblPADiabetic.lngVisitID          
WHERE (tblPAVisit.lngPatientID = @Paramid)        
UNION ALL          
SELECT dtmcontact as date, tblPAVisit.lngPatientID , tblPAVisit.lngVisitID, tblPAVoucher.memVoucher AS 'memo'  , 'Voucher Notes'as notetype        
FROM tblPAVoucher INNER JOIN tblPAVisit ON tblPAVoucher.lngVisitID = tblPAVisit.lngVisitID          
WHERE (tblPAVisit.lngPatientID = @Paramid) AND (tblPAVoucher.memVoucher IS NOT NULL)  
ORDER BY dtmcontact desc
0
 

Author Comment

by:running32
ID: 21825159
I get the error below when I try to run the query

Server: Msg 8626, Level 16, State 1, Procedure spPANotes, Line 9
Only text pointers are allowed in work tables, never text, ntext, or image columns. The query processor produced a query plan that required a text, ntext, or image column in a work table.
0
 

Author Comment

by:running32
ID: 21825241
there was a ntext value in the query.  thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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