Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got to do a filter based on checkbox selected. I got 5 search criteria's where I just posted 2. I would select styles and leave solid_yarn empty. So the sql function CSVToTable based on selected values are not working properly?

C#
if (style != null)
    {
        for (int i = 0; i < style.Length; i++)
        {
            parameterList.Append(style[i] + ",");
        }
        var parameters = parameterList.ToString().TrimEnd(',');
        cmd.Parameters.AddWithValue("@Liststyle", parameters);
    }

if (solid_yarn != null)
    {
        var parameterList1 = new StringBuilder();
        for (int i = 0; i < solid_yarn.Length; i++)
        {
            parameterList1.Append(solid_yarn[i] + ",");
        }
        var parameters1 = parameterList1.ToString().TrimEnd(',');
        cmd.Parameters.AddWithValue("@Listsolidyarn", parameters1);
    }


My CSVToTable function
SQL
ALTER FUNCTION [dbo].[CSVToTableStyle] (@InStr VARCHAR(MAX))
RETURNS @TempTab TABLE
   (Style varchar(MAX) not null)
AS
BEGIN
    ;-- Ensure input ends with comma
    SET @InStr = REPLACE(@InStr + ',', ',,', ',')
    DECLARE @SP INT
DECLARE @VALUE VARCHAR(1000)
WHILE PATINDEX('%,%', @INSTR ) <> 0 
BEGIN
   SELECT  @SP = PATINDEX('%,%',@INSTR)
   SELECT  @VALUE = LEFT(@INSTR , @SP - 1)
   SELECT  @INSTR = STUFF(@INSTR, 1, @SP, '')
   INSERT INTO @TempTab(Style) VALUES (@VALUE)
END
    RETURN
END


and My sql query in a stored procedure is as follows..

SQL
@Liststyle varchar(MAX)=null,
@Listsolidyarn varchar(MAX)=null,
select * from tbl_Pgm_Preview where (Brand=@brand) and (Department=@department) and (Season=@season) and (Group_Name=@groupname)
and (Style in ( Select * from dbo.[CSVToTableStyle](@Liststyle)))
and (Solid_yarn in ( Select * from dbo.[CSVToTableSolidYarn](@Listsolidyarn)))
Posted
Updated 11-Aug-14 23:33pm
v2
Comments
Kumarbs 12-Aug-14 5:32am    
Can you improve your question? It is not clear to understand.
Sriram Ramachandran 12-Aug-14 5:34am    
Simple: Got 5 search Checkboxes... I would select any of the one//two/.. checkboxes in order to search the data. If I search using all fields: Can get expected outcome. But When I select 1,2,3,4 out of 5(leaving any checkbox empty).. No records
Sriram Ramachandran 12-Aug-14 5:36am    
So I need to run the SQL function passing empty parameters also..
Kumarbs 12-Aug-14 5:39am    
Are you not able to pass the empty parameters or if you pass empty the expected result is not coming?
Sriram Ramachandran 12-Aug-14 5:41am    
yeah I just pass 1 parameter which has value and pass 4 parameters as empty.. No Records found... But there is a data ....
Even I tried passing null value

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