Solved

MS-SQL query question

Posted on 2012-12-21
5
275 Views
Last Modified: 2013-01-25
Hi I am doing a query using MSSQL Mgt Studio in design view ( because I no nothing). On MS SQL server 2005

SELECT     patient_name.*, patient_address.*, doctor.*
FROM         patient_name CROSS JOIN
                      patient_address CROSS JOIN
                      doctor

I need to limit the query to the past 12 months (so the server doesn't gag) and produce an output I can eventually import into Excel
0
Comment
Question by:Openallnight
[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
5 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 38713804
SELECT     patient_name.*, patient_address.*, doctor.*
FROM         patient_name CROSS JOIN
                      patient_address CROSS JOIN
                      doctor
where <myDatecolumn> > dateadd("m",-12,getdate())
0
 

Author Comment

by:Openallnight
ID: 38714162
I tried to grab billing dates from a billing submission table called reconsideration_table and it bombs

Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '<'.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 38714186
The server will gag from those CROSS JOINs, because they are inappropriate here.

Something like below will be close, although it's probably still not quite right, since there should be a "doctor_patient" table and/or a "patient_visit" table that would be more accurate to use for this.


SELECT     patient_name.*, patient_address.*, doctor.*
FROM         dbo.patient_name pn
INNER JOIN dbo.patient_address pa ON
    pa.patient_id = pn.patient_id
INNER JOIN dbo.doctor d ON
    d.doctor_id = pn.doctor_id
0
 
LVL 3

Accepted Solution

by:
expert_dharam earned 500 total points
ID: 38716034
SELECT     patient_name.*, patient_address.*, doctor.*
FROM         dbo.patient_name pn
INNER JOIN dbo.patient_address pa ON
    pa.patient_id = pn.patient_id
INNER JOIN dbo.doctor d ON
    d.doctor_id = pn.doctor_id
Where YourTableDateColumn > dateadd("m",-12,getdate())

--Note: YourTableDateColumn = Column where your date values reside in the table
--Ensure YourTableDateColumn is of Datetime data type..
0
 

Author Comment

by:Openallnight
ID: 38732966
Too many errors, I don't know enough about SQL to interpret directions
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Impove long SQL Stored Procedure Performance 14 79
Help with simplifying SQL 6 54
Can Unique column have more than one Null? 8 61
SCOM monitoring possibilities? 9 37
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

733 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