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 2008 Forums
 Transact-SQL (2008)
 SQL Split function

Author  Topic 

Sqlmm
Starting Member

3 Posts

Posted - 2011-10-03 : 03:19:58
Hello i have this SQl function, what i need to do is, make a split function. i have some tags, and i need to split my tags by using the split function, someone can help for a code to do that ?
Create FUNCTION [dbo].[TEST]
(
-- Add the parameters for the function herezs
@TagList varchar(4000)
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT
StartTime, EndTime, Node, Tag, OPCItemID, EventText, Event, Value
FROM
NRPVM_plantdatabase.dbo.vw_AlarmHistory

where OPCItemID = @TagList

)

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-10-03 : 03:52:18
One of these will help you.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

OR

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-03 : 03:52:42
see

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vmvadivel
Yak Posting Veteran

69 Posts

Posted - 2011-10-03 : 04:16:45
Also check out this - http://vadivel.blogspot.com/2011/10/how-to-split-delimited-string-values-in.html

Best Regards
Vadivel

http://vadivel.blogspot.com
Go to Top of Page

Sqlmm
Starting Member

3 Posts

Posted - 2011-10-12 : 05:32:15
thank for the response, but i think that i cant use the create function because i cant use the select statement, what about if i use the stored procedure ? any ideas how the split function will look like ?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-10-12 : 05:42:40
It really depends how you want to go about it. The other way is to use a CLR function to split the string. This is faster in nearly all cases and you can then just join to the function. See http://www.sommarskog.se/arrays-in-sql-2005.html#CLR for more on this. If speed is not an issue, then you can use a function and simply join in your select statement to the function.

so to split a strng with CLR you would create the CLR and create the assembly, then you could simply run sometyhing like the following:

SELECT DISTINCT
number AS OPCItemID
FROM
CLR_intlist_iter(@@TagList,',')
Go to Top of Page
   

- Advertisement -