Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Dynamically calling UDF to update a table

Author  Topic 

Bigjim
Starting Member

1 Post

Posted - 2005-12-07 : 21:25:26
I created a temp table to hold ID and Discrepancy. Initially Discrepancy has a comma delimited format so I then call the function fnAcctDiscSplit which returns a table of the ID, Disc.
So fnAcctDiscSplit(10, 'p,b,c', ',') returns 10 p:10 b:10 c. I then want to insert that whole table back into this/any table. Can this be done?

Here is my attempt at it:
Insert into #tmp(ID, Discrepancy)
Select s.ID, s.Discrepancy
from #Tmp t
JOIN fnAcctDiscSplit(t.ID, t.Discrepancy, ',') as s
ON s.ID = t.ID

Thanks,
Big Jim

Kristen
Test

22859 Posts

Posted - 2005-12-08 : 01:02:20
So ...

from #Tmp t
JOIN fnAcctDiscSplit(t.ID, t.Discrepancy, ',') as s
ON s.ID = t.ID

is so that you can "split" the values for ALL the rows in #Tmp ??

You can't do that this way. You will either have to loop round the rows in #Tmp and process then one-by-one through fnAcctDiscSplit, or create a "multi-row-split" method. You'd probably need a TALLY table to do that - here's an example:

http://www.sqlteam.com/item.asp?ItemID=5857

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-08 : 01:10:02
>>Initially Discrepancy has a comma delimited format

Hereafter use Proper Normalisation
http://www.datamodel.org/NormalizationRules.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -