|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: 2 days ago @ 9:28 AM
Points: 228,
Visits: 280
|
|
I was considering using CLR to write a table-valued function that can accept an array argument and return the elements as a table. I cannot work out a way of achieving what I need using TSQL but maybe you do?!
Thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 11:35 AM
Points: 5,734,
Visits: 6,917
|
|
The big question in my mind would be - what is it you see using this for? do you have a specific example in mind?
Understanding the background could be really helpful.
For what it's worth - Jeff Moden has an article on emulating multi-dimension arrays being passed in. It posted last week as I recall. Might be worth starting there.
---------------------------------------------------------------------------------- Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 8:02 PM
Points: 16,187,
Visits: 8,831
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: 2 days ago @ 9:28 AM
Points: 228,
Visits: 280
|
|
Jeff/Matt,
Thanks for your help, I've decided to go down the Tally table route as it suits what I need with very little effort.
BTW Jeff, good article on Tally tables!
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 8:02 PM
Points: 16,187,
Visits: 8,831
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, June 30, 2009 10:36 AM
Points: 474,
Visits: 163
|
|
I personal like xml for these situations.
And here is my why of implementing this
Options---> // // // // ProuductID --> //= 7
ALTER FUNCTION [dbo].[SplitList] ( @list AS XML ) RETURNS TABLE AS RETURN ( SELECT tempTable.item.value('.', 'VARCHAR(MAX)') AS ProductID FROM @list.nodes('list/item') tempTable(item) );
ALTER PROC [dbo].[uspUtbProduct_Options_Update_Ext]
@List XML, @ProductID INT, @UpdateFalse0InsertTrue1 BIT
AS
SET NOCOUNT ON;
DECLARE @ProductOptionIDs INT, @Cnt INT, @ProductOptionID INT; DECLARE @TableVar table (ID int identity(1,1) PRIMARY KEY, ProductID INT NOT NULL ) INSERT INTO @TableVar(ProductID) SELECT ProductID FROM [SplitList](@List);
SELECT @Cnt = LEN(ProductID) FROM [SplitList](@List)
WHILE(@Cnt > 0) BEGIN
SELECT @ProductOptionID = ProductID FROM @TableVar WHERE ID = (@Cnt);
IF(@UpdateFalse0InsertTrue1 = 0) BEGIN
UPDATE Production.utbProductUtbProductOption SET ProductOptionID = @ProductOptionID WHERE Production.utbProductUtbProductOption.ProductID = @ProductID END
IF(@UpdateFalse0InsertTrue1 = 1) BEGIN INSERT INTO [Production].[utbProductUtbProductOption] ([ProductID] ,[ProductOptionID]) VALUES (@ProductID ,@ProductOptionID) END
SET @Cnt = @Cnt-1 END
SET NOCOUNT OFF;
protected void btnAddOpts_Click(object sender, EventArgs e) { HiddenField hdn = null; CheckBox ckBx = null; ArrayList prodIDs = null; ProductsDataContext pc = null; try { prodIDs = new ArrayList(); for (short i = 0; i < this.lvProdOpts.Items.Count; i++) { ckBx = this.lvProdOpts.Items[i].FindControl("ckBx") as CheckBox; if (ckBx.Checked) { hdn = this.lvProdOpts.Items[i].FindControl("hdn") as HiddenField; prodIDs.Add(int.Parse(hdn.Value)); } } if (prodIDs.Count > 0) { pc = new ProductsDataContext(); int res = pc.uspUtbProduct_Options_Update_Ext (GetXml(prodIDs), int.Parse(this.ViewState["ProductID"].ToString()), true);
this.LoadListViewProductOptions(); }
// // // // } //7 catch (Exception) { } hdn = null; ckBx = null; prodIDs = null; pc = null; }
public static XElement GetXml(ArrayList list) { XElement x = new XElement("list");
foreach (int prodID in list) { x.Add(new XElement("item", prodID)); }
return x;
}
There's my side and there's your opinion !
|
|
|
|