Pass Table Name to a function dynamically
-
Hi i need to pass table name and to a function dynamically anyone can help
Mohammad Al Hoss Development To Me Is A Pleasure more than a Job
-
Hi i need to pass table name and to a function dynamically anyone can help
Mohammad Al Hoss Development To Me Is A Pleasure more than a Job
-
Hi i need to pass table name and to a function dynamically anyone can help
Mohammad Al Hoss Development To Me Is A Pleasure more than a Job
I knew this would come up sooner or later. SQL Server Central had an article (sorry no link) that used XML to pass the table and data to a function. Stored proc expamle
Declare @X xml Set @X = (SELECT RegionID, sum(Amount) Amount FROM FactTran where PeriodID = @PeriodID and WFGroupID = @WFGroupID and TranTypeID = @TranTypeID and ISNULL(BUID,7) = 7 Group By RegionID For XML Raw ('RegionID'), ROOT('Regions'))
Function exampleLEFT OUTER JOIN (SELECT x.item.value('@RegionID[1]', 'VARCHAR(100)') AS RegionID, x.item.value('@Amount[1]', 'Decimal(30,2)') AS Amount FROM @x.nodes('//Regions/RegionID') AS x(item)) R on R.RegionID = A.RegionID
These are my usage and may give you some idea if you cannot find the article.Never underestimate the power of human stupidity RAH