Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

SQL querry

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
EdFernan1016
Asked:
EdFernan1016
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
RickCooperCommented:
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
 
8080_DiverCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now