Solved

MS-SQL query question

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
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.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

729 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