Solved

SQL querry

Posted on 2009-04-08
5
314 Views
Last Modified: 2012-05-06
I am trying to run this querry to print the data order by string ID and  yes or no, when I run the code  there is no results of the data. Is there a  syntax error  on the querry?
String strCmd = "select practicies.practice, " +
				"practicies.www, " +
				"addresses.street_address, " +
				"addresses.street_address_2, " +
				"addresses.street_address_3, " +
				"addresses.city, " +
				"addresses.zip, " +
				"addresses.county, " +
				"addresses.state, " +
				"xr_physician_practice_address.physician_id, " +
				"xr_physician_practice_address.practice_id, " +
				"xr_physician_practice_address.address_id " +
				//"xr_physician_practice_address.primary_yn"+
				"from  addresses " +
				"inner join practicies " +
				"on practicies.practice_id = addresses.practice_id " +
				"inner join  xr_physician_practice_address " +
				"on addresses.address_id  = xr_physician_practice_address.address_id " +
				"where xr_physician_practice_address.physician_id =" + strID +
				" and xr_physician_practice_address.primary_yn=y ";

Open in new window

0
Comment
Question by:EdFernan1016
[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 57

Expert Comment

by:Raja Jegan R
ID: 24102533
There are no Order by Clause in your Query:
What is the String Id and Yes or No columns you refer to

Add those columns as given below

ORDER BY stringid_column, yes_no_column

In addition to that

xr_physician_practice_address.primary_yn=y
=y should be in single or double quotes based upon your database type either SQL Server or Oracle like = 'y' or = "y"

Other than that, there are no issues in the query
0
 
LVL 1

Accepted Solution

by:
RickCooper earned 500 total points
ID: 24102534
Try this on the last two lines

"where xr_physician_practice_address.physician_id ='" + strID +"'" +
                                " and xr_physician_practice_address.primary_yn='y' ";

I've added a single quote around the strID and the y
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24102586
If you have access to a SQL Query Tool that lets you execute queries against your database, try executing the following SQL_1 query (substituting a reasonable value for the "strid".  If it works, then try the SQL_2 query.  The difference is in the case of the 'Y' . . . your database may be case sensitive and, if so, there is a difference between 'Y' and 'y'.
I highly recommend using UPPER case for all reserved words and for any Y/N indicators that you use in your database. ;-)

SQL_1:
 
select p.practice, 
       p.www, 
       a.street_address, 
       a.street_address_2, 
       a.street_address_3, 
       a.city, 
       a.zip, 
       a.county, 
       a.state, 
       x.physician_id, 
       x.practice_id, 
       x.address_id 
from   addresses a
inner join practicies p
   on  p.practice_id = a.practice_id 
inner join  xr_physician_practice_address x
   on  a.address_id  = x.address_id 
where  x.physician_id = strID 
  and  x.primary_yn='Y' ;
 
 
SQL_2:
 
select p.practice, 
       p.www, 
       a.street_address, 
       a.street_address_2, 
       a.street_address_3, 
       a.city, 
       a.zip, 
       a.county, 
       a.state, 
       x.physician_id, 
       x.practice_id, 
       x.address_id 
from   addresses a
inner join practicies p
   on  p.practice_id = a.practice_id 
inner join  xr_physician_practice_address x
   on  a.address_id  = x.address_id 
where  x.physician_id = strID 
  and  x.primary_yn='y' ;

Open in new window

0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

733 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