Solved

SQL querry

Posted on 2009-04-08
5
313 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS RDS Backups? 3 51
Database Design Dilemma 6 58
TSQL Query Into Specific XML Format w/ Multiple Groupings 6 33
Procedure syntax 5 38
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

839 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