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.
Arul Manivannan48 reputationPosted Mar 19, 2013, 1:20 AM EDT
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
Sreejesh SPRank #1,975 · 740 reputationPosted Mar 18, 2013, 11:20 PM EDT
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
Pradip PandeyRank #452 · 5.6K reputationPosted Mar 19, 2013, 12:36 AM EDT
Hope it will help.
Sreejesh SPRank #1,975 · 740 reputationPosted Mar 19, 2013, 12:58 AM EDT
He want insertion query
thanks
sreejesh
Pradip PandeyRank #452 · 5.6K reputationPosted Mar 19, 2013, 1:51 AM EDT
Arul you are right and hope sreejesh will also get the question.
Hope it will help.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts