Solved

MS-SQL query question

Posted on 2012-12-21
5
287 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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 we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

623 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