I have a table with 10 field ..
name , fname, mobile, area, hno,,refid,refname,refadd,refmob,dob
.....
how to write storedprocedure quarie....display only distinct name and mobile...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arul ManivannanPosted Mar 19, 2013, 5:20 AM
Pradip Pandey's solution seems correct. So thumbs upped that reply. sv r said he wants to display, not to insert into that table.
Please execute the following
CREATE PROCEDURE sp_displayNameMobile
AS
BEGIN
SELECT DISTINCT name, mobile from tablename
END
Arul Manivannnan
Pradip PandeyPosted Mar 19, 2013, 5:51 AM
Arul you are right and hope sreejesh will also get the question.
Hope it will help.
Sreejesh SPPosted Mar 19, 2013, 4:58 AM
He want insertion query
thanks
sreejesh
Pradip PandeyPosted Mar 19, 2013, 4:36 AM
Hope it will help.
Sreejesh SPPosted Mar 19, 2013, 3:20 AM
First you set your table field unique as name and mobile
create procedure usp_address
(
@name varchar(50),
@fname varchar(50),
@area varchar(50),
@hno numeric(18,0),
@rfid numeric(18,0),
@refname varchar(50),
@refadd varchar(50),
@refmob varchar(50)
@dob varchar(50)
)
DECLARE @AFFECTEDROWS INT
DECLARE @Message VARCHAR(1000)
AS
BEGIN TRAN
BEGIN TRY
INSERT INTO TABLE1(name,fname,mobile,area,hno,refid,refname,refadd,refmob,dob)
VALUES(@name ,@fname ,@area ,@hno ,@rfid ,@refname ,@refadd ,@refmob ,@dob )
SET @AFFECTEDROWS =@@ROWCOUNT;
IF(@AFFECTEDROWS<=0)
BEGIN
ROLLBACK TRAN
END
ELSE
BEGIN
COMMIT TRAN
END
END TRY
BEGIN CATCH
SET @Message = ERROR_MESSAGE();
PRINT @Message
END CATCH
PLEASE TRY THIS CODE
THANKS
SREEJESH