.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to get result,just passing table name,column name and value

Posted By:Santosh       Posted Date: October 15, 2010    Points: 15    Category: SQL Query    URL: http://www.dotnetspark.com  

for this sp u need to pass the tablename,columnname and the value. tablename is the table from where u will get result,column name is the where condition..
 

Below SP will give u the result for passing table name,columnname and values

ALTER PROC TEST
@VALUE VARCHAR(10) = NULL
,@COLUMNNAME VARCHAR(100)= NULL
,@TABLENAME VARCHAR(100)= NULL
AS
BEGIN
DECLARE @QUERY  VARCHAR(100)
DECLARE @COUNT1 VARCHAR(10)  
PRINT @VALUE
--DECLARE @UPDATEDATAVALUE VARCHAR(7000)
SET @QUERY = 'SELECT * FROM  ' + @TABLENAME  + '  WHERE ' + @COLUMNNAME + ' = ' + @VALUE
PRINT @QUERY
 EXEC(@QUERY)

RETURN 0
END

-- EXEC TEST @TABLENAME = 'USERMST',@COLUMNNAME = 'USERID',@VALUE = 118

here USERMST is my table name,USERID is my columnname and @VALUE  = i want


Regards
Santosh




     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend