ASP.NET - How to pass Table records as variable in scan all record til matching criteria

Asked By bhanupratap singh on 25-Feb-13 07:24 AM
I want to pass table record to variable to match with parameter name throughout the table to search specific record with using while loop if else
who to do 

Jatin Trikha replied to bhanupratap singh on 26-Feb-13 05:35 AM
As per my understanding you want to pass value to a storedprocedure and get the record in which that value is present. It simple create a SP as follow


Create Procedure FindRecord @value nvarchar(max)
as
(
select * from you table where colum= @value
)


if you want to iterate across all the columns starting from first record update the sp definition as following
You have to iterate of identity column.


Create Procedure FindRecord @value nvarchar(max)
as
(
DECLARE @COUNT1 AS INT = 0,
        @COUNT2 AS INT = 0,
    

SELECT @COUNT1 = COUNT(*) FROM yourtable

WHILE @COUNT1 > @COUNT2
BEGIN
    SET @COUNT2 = @COUNT2 + 1
    IF EXISTS(SELECT 1 FROM yourtable WHERE (youidentitycol = @COUNT2 ) AND ( col1 = @value  OR col2 = @value))
    begin
    SELECT * FROM yourtable WHERE (youidentitycol = @COUNT2 ) AND ( col1 = @value  OR col2 = @value)  
    BREAK
    end
END


)
bhanupratap singh replied to Jatin Trikha on 28-Feb-13 01:44 AM
thanks for reply
bhanupratap singh replied to Jatin Trikha on 28-Feb-13 01:44 AM
thanks for reply