Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.


Reply With Quote
  #2 (permalink)  
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
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:11 AM.


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