473,326 Members | 2,168 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,326 software developers and data experts.

Stored Procedure

44
Hi

I have to convert the following query into stored procedure

"select DoctorMaster.FirstName+''+DoctorMaster.MiddleName+ ''+DoctorMaster.LastName as DoctorsName,DoctorMaster.DRID,DoctorMaster.Gender, DrClinicDetails.Address,DoctorMaster.Telephone+',' +DoctorMaster.Mobile as Phone,PrimaryTitle.PrimaryTitle from DoctorMaster,DrClinicDetails,PrimaryTitle,Specialt y where DoctorMaster.FirstName like '" + obj.ToString() + "%' or Specialty.Specialty='" + obj1.ToString() + "' or DoctorMaster.City='" + obj2.ToString() + "' and DoctorMaster.DRID=DrClinicDetails.DRID and DoctorMaster.SPID=Specialty.SPID and PrimaryTitle.PTID=DoctorMaster.PrimaryTitleID"

For that I have written the stored procedure as

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Pro_Grid]

@FirstName nvarchar(100)output,
@MiddleName nvarchar(100)output,
@LastName nvarchar(100)output,
@DRID nvarchar(12)output,
@Gender bit output,
@Address nvarchar(255)output,
@Telephone nvarchar(50)output,
@Mobile nvarchar(50)output,
@PrimaryTitle nvarchar(20)output,
@Specialty nvarchar(50)output,
@City nvarchar(100)output
@SPID nvarchar(12)output,
@PTID nvarchar(12)output,
@PrimaryTitleID nvarchar(12)output


AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.


-- Insert statements for procedure here
-- select @SPID=SPID,@Specialty=Specialty from Specialty

select DoctorMaster.FirstName+''+DoctorMaster.MiddleName+ ''+DoctorMaster.LastName as DoctorsName,DoctorMaster.DRID,DoctorMaster.Gender, DrClinicDetails.Address,DoctorMaster.Telephone+',' +DoctorMaster.Mobile as Phone,PrimaryTitle.PrimaryTitle from DoctorMaster,DrClinicDetails,PrimaryTitle,Specialt y where DoctorMaster.FirstName like DoctorMaster.@FirstName or Specialty.Specialty=Specialty.@Specialty or DoctorMaster.City=DoctorMaster.@City and DoctorMaster.DRID=DrClinicDetails.DRID and DoctorMaster.SPID=Specialty.SPID and PrimaryTitle.PTID=DoctorMaster.PrimaryTitleID
-- insert into Specialty (SPID,Specialty)
-- values(@SPID,@Specialty)

END

But if I execute, I got the error as

Msg 102, Level 15, State 1, Procedure Pro_Grid, Line 20
Incorrect syntax near '@SPID'.
Msg 102, Level 15, State 1, Procedure Pro_Grid, Line 34
Incorrect syntax near '@FirstName'.
Jul 3 '08 #1
1 1041
deepuv04
227 Expert 100+
CREATE PROCEDURE [dbo].[Pro_Grid]

@FirstName nvarchar(100),
@Specialty nvarchar(50),
@City nvarchar(100)


AS
BEGIN

select DoctorMaster.FirstName+''+DoctorMaster.MiddleName+ ''+DoctorMaster.LastName as DoctorsName,
DoctorMaster.DRID,DoctorMaster.Gender, DrClinicDetails.Address,
DoctorMaster.Telephone+',' +DoctorMaster.Mobile as Phone,
PrimaryTitle.PrimaryTitle
from DoctorMaster,DrClinicDetails,PrimaryTitle,Specialt y
where (DoctorMaster.DRID=DrClinicDetails.DRID and
DoctorMaster.SPID=Specialty.SPID and
PrimaryTitle.PTID=DoctorMaster.PrimaryTitleID) AND
(DoctorMaster.FirstName like @FirstName + '%' or
Specialty.Specialty = @Specialty or
DoctorMaster.City = @City )

END

To execute the procedure
Exec Pro_Grid 'firstname','speciality','city'
Jul 3 '08 #2

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

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.