473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Selecting Query

39
DoctorMaster

DRID nvarchar(50)
FirstName nvarchar(100)
LastName nvarchar(100)
Gender bit
Address1 nvarchar(255)
Address2 nvarchar(255)
City nvarchar(100)
Pincode numeric(6,0)
State nvarchar(100)
Country nvarchar(100)
Telephone nvarchar(50)
Mobile nvarchar(50)
EmailID nvarchar(100)
Designation nvarchar(50)
Suffix nvarchar(100)
Language nvarchar(10)
SpecialityId nvarchar(100)

Speciality

SPID nvarchar(12)
Speciality vnarchar(50)

DrClinicDetails

DRID nvarchar(12)
CDID nvarchar(12)
HPID nvarchar(12)
HospitalName nvarchar(50)
Address1 nvarchar(255)
Address2 nvarchar(255)
VisitOn char(1)
weekly nvarchar(15)
monthly datetime
status char(1)


I have

Name_TextBox
Specialty_DropDownList
Location_DropDownList

in my page. According to the data in above 3 controls I have to select the value from DB by using the above 3 tables. The selected should be like below

Name: (by appending FirstName,LastName & MiddleName from DoctorMaster)
Gender: From DoctorMaster
Address1: From DrClinicDetails
Phone: (by appending Telephone,Mobile from DoctorMaster)
Suffix: From DoctorMaster

where

FirstName(from DoctorMaster table)=Name_TextBox
Specialty(from specialty table)=Specialty_DropDownList
Country(from DoctorMaster)=Location_DropDownList

The query I have given in .Net is

Select DM.FirstName||DM.MiddleName||DM.LastName "Doctors Name",DM.Gender,DC.Address1,DM.Telephone||DM.Mobil e "Phone",DM.Suffix from DoctorMaster DM,DrClinicDetails DC,Specialty SP where DM.FirstName='aaa' or SP.Specialty='001' or DM.Country='India' and SP.SPID='001'

Its not working.
Jun 23 '08 #1
4 1215
deepuv04
227 Expert 100+
Hi,
Try the query in the following way...

Expand|Select|Wrap|Line Numbers
  1. Select DM.FirstName + '||' + DM.MiddleName + '||' + DM.LastName AS Doctors Name,
  2.        DM.Gender,DC.Address1,DM.Telephone + '||' + DM.Mobile AS Phone,
  3.        DM.Suffix 
  4. from DoctorMaster DM INNER JOIN 
  5.      DrClinicDetails DC DM.DRID  = DC.DRID  INNER JOIN
  6.      Specialty SP SP.SPID = DM.SpecialityId  
  7. where ( DM.FirstName='aaa' or SP.Specialty='001' or DM.Country='India') and SP.SPID='001'
  8.  
  9.  
thanks
Jun 23 '08 #2
suganya
39
Hi

If I run the following query in sql server 2005, its displaying the data.

Select DM.FirstName+' '+DM.MiddleName+' '+DM.LastName "DoctorsName",DM.Gender,DC.Address,DM.Telephone+DM .Mobile "Phone",PT.PrimaryTitle from DoctorMaster DM,DrClinicDetails DC,Specialty SP,PrimaryTitle PT where DM.FirstName='aaa' or SP.Specialty='aaa' or DM.City='madurai' and SP.SPID=DM.SPID and PT.PTID=DM.PrimaryTitleID

But if I give the same query as

string sql="Select DM.FirstName+''+DM.MiddleName+''+DM.LastName "DoctorsName",DM.Gender,DC.Address,DM.Telephone+'' +DM.Mobile "Phone",PT.PrimaryTitle from DoctorMaster DM,DrClinicDetails DC,Specialty SP,PrimaryTitle PT where DM.FirstName='" + obj.ToString() + "' or SP.Specialty='" + obj1.ToString() + "' or DM.City='" + obj2.ToString() + "' and SP.SPID=DM.SPID and PT.PTID=DM.PrimaryTitleID";

in asp.net then it is showing the error as

; expected
Jun 23 '08 #3
suganya
39
Than U Deepuv04. Its not showing any error but still I have a doubt, in the above query if I add another table

PrimaryTitle

PTID nvarchar(12)
PrimaryTitle nvarchar(20)

and give the query like

Select DM.FirstName + '' + DM.MiddleName + '' + DM.LastName AS DoctorsName, DM.Gender,DC.Address,DM.Telephone + '' + DM.Mobile AS Phone,PT.PrimaryTitle from DoctorMaster DM INNER JOIN DrClinicDetails DC DM.DRID = DC.DRID INNER JOIN Specialty SP SP.SPID = DM.SPID INNER JOIN PrimaryTitle PT PT.PTID=DM.PrimaryTitleID where ( DM.FirstName like 'a' or SP.Specialty='aaa' or DM.City='madurai')


It is showing the following error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'DM'.
Jun 24 '08 #4
deepuv04
227 Expert 100+
Hi,
coming to your first error, since you are building the query as a string in .net you need to follow the .net syntax to build the string. like when you are moved to next line you need to add " & _" at the end of previous.

the code will be:
Expand|Select|Wrap|Line Numbers
  1.  
  2. string sql="Select DM.FirstName+''+DM.MiddleName+''+DM.LastName  ""DoctorsName""," & _
  3.            "DM.Gender,DC.Address,DM.Telephone+''+DM.Mobile ""Phone"",PT.PrimaryTitle " & _
  4.            "from DoctorMaster DM,DrClinicDetails DC,Specialty SP,PrimaryTitle PT " & _
  5.            "where (DM.FirstName='" + obj.ToString() + "' or SP.Specialty='" + obj1.ToString() + "' or DM.City='" + obj2.ToString() + "')" & _
  6.            " and SP.SPID=DM.SPID and PT.PTID=DM.PrimaryTitleID";
  7.  
about second error: you missed the key word "ON" in the joining syntax.
the code is:
[code =sql]
Select DM.FirstName + '' + DM.MiddleName + '' + DM.LastName AS DoctorsName,
DM.Gender,DC.Address,DM.Telephone + '' + DM.Mobile AS Phone,PT.PrimaryTitle
from DoctorMaster DM INNER JOIN
DrClinicDetails DC on DM.DRID = DC.DRID INNER JOIN
Specialty SP on SP.SPID = DM.SPID INNER JOIN
PrimaryTitle on PT PT.PTID=DM.PrimaryTitleID
where ( DM.FirstName like 'a' or SP.Specialty='aaa' or DM.City='madurai')
[/code]
Jun 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul Bradford | last post by:
I have a query that takes about two minutes and returns 97 rows. If I change the query only by adding ROWNUM to the outermost select clause, the query never returns (I let it run overnight). I'm...
2
by: John | last post by:
Hello, I have a table called BUILDREQUESTS which I want to select from, depending on the project ID of each record. The Project ID field is indexed. (A) This query runs almost instantly: ...
4
by: Lucius | last post by:
Hello everyone, I have a query problem. I'll put it like this. There is a 'publishers' table, and there is a 'titles' table. Publishers publish titles (of course). Now I want to make a query (in...
4
by: Doslil | last post by:
I have a form which has a subform.In the main form I have only one field (this is a drop down list and has a query attached to it) which selects empno,Name from the EmployeeInformation table. ...
4
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student...
8
by: Henrik Larsson | last post by:
Hi, I need help with selecting the following rows from a table looking like this: ID IP Query 1 -> 1 2.2.2.2 (ie first IP 1 1.1.1.1 <- Query 2 for each...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
8
by: Lewe22 | last post by:
I have a basic query which is selecting all information from another query . As soon as i set the query to show the totals (in order to perform a sum) all information held in a field named is...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.