Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL querry

Posted on 2009-04-08
5
Medium Priority
?
317 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 1500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

604 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