.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 >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

How to check given value exist in the given table column?

Posted By: Sajid P K     Posted Date: October 12, 2010    Points:2   Category :Sql Server
Can any one please tell me. what is the most efficient way for following task?





I have to check given value exist in the given table.



Input parameter...



TableName , ColumnName, Value.


Responses
Author: Syed Shakeer Hussain             
Posted Date: October 12, 2010     Points: 5   

Hi,

Run below T-Sql to check given value exist in the given table.


Declare @tablename as varchar(100)
Declare @columname as varchar(100)
Declare @value as varchar(100)
set @tablename='UserDetails'
set @columname='UserID'
set @value=6
IF EXISTS (
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =@tablename AND COLUMN_NAME = @columname)
BEGIN
select * from UserDetails where @columname=@value
END




Author: Asha.MP             
Posted Date: October 12, 2010     Points: 5   

Hi..

You can use below query for that

select count(*)
from TableName
where ColumnName=value

I think this is one of the Efficient query.

Thanks and Regards,
Asha.mp
Author: Santosh             
Posted Date: October 15, 2010     Points: 5   

just follow below link..

http://www.dotnetspark.com/kb/Content.aspx?id=2772

hope this will help u....

Regards
Santosh

Author: Ramesh P             
Posted Date: October 19, 2010     Points: 5   

IF EXISTS is a efficient way to check whether the value or not. It will scan only one row of the table if the rows exist in a table. But count(*) function will scan entire row result.

syntax:

IF EXISTS(select * from tablename where columname=value)
begin
//write a statement
end

Regards,


Ramesh

Author: sriram             
Posted Date: October 27, 2011     Points: 20   

select * from TableName
where ColumnName=value

regards
sriram.R



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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