Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2007, 04:56 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Query Syntax

Hello Everyone and thanks for your help in advance. I am wokring on a query that unfortunately, I am unable to post any data due to privacy issues (albeit test data). However, here is what I am trying to accomplish. Let's assume I make an initial single query to the tblPatientVisit table

Select MRNumber From tblPatientVisits Where VisitDate > '1/1/2005'

Should return numerous records to the tune of

MRNumber

3122

3122

3122

etc.

I now want to take the results of this query (it should return several thousand records with multiple occurrences of the same MRNumber) and query it against the tblPtmstr table to return each individual visit's zip code. For example:

MRNumber Zip Code

3122 34120

3122 34120

3122 34120

TI've tried numerous JOINS but always seem to miss data. Thanks for the assistance.


 
Old May 1st, 2007, 06:42 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

hmmm. What is the relationship tblPatientVisit and tblPtmstr? Assuming that there is a relationship between the 2 tables based on the column MRNumber this should work:

SELECT
   v.MRNumber,
   p.ZipCode
FROM tblPatientVisit v
LEFT JOIN tblPtmstr p on v.MRNumber = p.MRNumber
WHERE Convert(varchar(10), v.VisitDate, 101) = '01/01/2005'

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Query digby_dog SQL Server 2000 2 September 8th, 2005 08:37 AM
Query syntax problem mateenmohd Access 2 October 12th, 2004 11:33 PM
MySQL syntax in query Tachyon Beginning PHP 1 June 26th, 2004 08:42 PM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
QUERY SYNTAX singh_ginni Oracle 1 September 10th, 2003 07:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.