See:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CSV,Splitting%20delimited%20lists,Best%20split%20functionsfor how to handle/split a delimited list in a stored procedure.I've just been doing one today FWIW:We have a web page with a list of "options" for a product. Some require a Qty, some are just CheckBoxes. Trouble is the <INPUT type="text"> for the Qty ones always return a value (i.e. including empty) and the <INPUT type="checkbox"> ONLY return a value if they are checked.So what I have done is:<input type="checkbox" value="MyProductCode1" name="OPTION_CHECK" id="OPTION_CHECK" /><input type="checkbox" value="MyProductCode2" name="OPTION_CHECK" id="OPTION_CHECK" />...<input type="text" name="OPTION_QTY" id="OPTION_QTY" value="" /><input type="hidden" value="MyProductCode3" name="OPTION_PRODUCT" id="OPTION_PRODUCT" /><input type="text" name="OPTION_QTY" id="OPTION_QTY" value="" /><input type="hidden" value="MyProductCode4" name="OPTION_PRODUCT" id="OPTION_PRODUCT" />...
and I then get 3 arrays in the REQUEST.FORM object:OPTION_CHECKOPTION_PRODUCTOPTION_QTYOPTION_CHECK has a list of the Product Codes that were checked - the un-checked ones are "missing"OPTION_PRODUCT and OPTION_QTY have the same number of items, in the same order and contain one element for each product.I pass these three arrays, as comma delimited lists, to my SProc and process them as follows:CREATE PROCEDURE dbo.DNG_SP_SOP_ORDD_Customise_Save @OPTION_PRODUCT varchar(8000) = NULL, -- Product Code List @OPTION_QTY varchar(8000) = NULL, -- Qty List (synchronised with @OPTION_PRODUCT) @OPTION_CHECK varchar(8000) = NULL, -- Checkboxes - list of Product Codes checked ...DECLARE @OptionList TABLE( T_ProductCode varchar(100) NOT NULL, T_Qty int NOT NULL, PRIMARY KEY ( T_ProductCode ))-- NOTE: "MySplitFunction" returns a table with columns [Item] & [Value]INSERT @OptionList(T_ProductCode, T_Qty)SELECT [T_ProductCode] = LTrim(RTrim(P.Value)), [T_Qty] = COALESCE(NullIf(Q.Value, ''), 0)FROM dbo.MySplitFunction(@OPTION_PRODUCT, ',') AS P LEFT OUTER JOIN dbo.MySplitFunction(@OPTION_QTY, ',') AS Q ON Q.Item = P.Item -- The two lists are synchronised, link them togetherWHERE NullIf(LTrim(RTrim(Q.Value)), '') IS NOT NULLUNION ALLSELECT [T_ProductCode] = LTrim(RTrim(C.Value)), [T_Qty] = 1FROM dbo.MySplitFunction(@OPTION_CHECK, ',') AS CWHERE NullIf(LTrim(RTrim(C.Value)), '') IS NOT NULL
Kristen