Openallnight
asked on
MS-SQL query question
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
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
ASKER
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 '<'.
Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '<'.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Too many errors, I don't know enough about SQL to interpret directions
FROM patient_name CROSS JOIN
patient_address CROSS JOIN
doctor
where <myDatecolumn> > dateadd("m",-12,getdate())