Solved

SQL querry

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now