Skip to content Skip to sidebar Skip to footer

Sql Server 2008 T-sql Udf Odds And Ends

I am trying to take a data string from one column and split it into several different columns in SQL Ser 2008. Eample: Name Account 445566 0010020056893010445478008 AFD 369. I'm us

Solution 1:

To use a table valued udf against a table, you need CROSS APPLY (or maybe OUTER APPLY depending on how you want to deal with "no rows" from the udf). This applies the row-by-row operation of the udf against your table which itself is a table

SELECT
   *
FROM
   mytable M
   CROSS APPLY
   [dbo].[Split] (M.TheColumn) S 

To INSERT

INSERT AnotherTable (col1, col2, ...)
SELECT
   col1, col2, ...
FROM
   mytable M
   CROSS APPLY
   [dbo].[Split] (M.TheColumn) S 

Post a Comment for "Sql Server 2008 T-sql Udf Odds And Ends"