Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have to pass a variable to stored procedure and match the value with database table value and also count that record will not more than 1 and return that particular column data.
Posted

1 solution

Hi,

Check this ...Sql Server - How to write a Stored procedure in Sql server[^]


Also, as per your req. find below structure.

SQL
CREATE PROC PR_TEST
(
@PA_VAR1 VARCHAR(100)
)
AS
BEGIN

DECLARE @CNT INT



SELECT @CNT=COUNT(*) FROM YOUR_TABLE WHERE COL=@PA_VAR1

IF @CNT > 1
BEGIN

 SELECT 'VALID' 

END
ELSE
BEGIN

  SELECT 'INVALID' 

END

END


Hope above will help you.


Cheers
 
Share this answer
 
v2
Comments
Naveen Singh 16-Sep-14 4:07am    
thanks Magic Wonder but i have one more query that how could i check the uniqueness of that record in database ?because it that record is replicated that i have to return invalid request message
Magic Wonder 16-Sep-14 4:24am    
Check edited version.
Naveen Singh 16-Sep-14 4:28am    
thank you so much Magic Wonder it really works for me..!
Magic Wonder 16-Sep-14 4:31am    
Your welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900