[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp.net, sql

Posted on 2011-05-10
4
Medium Priority
?
251 Views
Last Modified: 2012-08-13
Trying to create function but have error
'Incorrect syntax near the keyword "WITH'.
LINE 17: INCORRECT SYNTAX NEAR ')'

CREATE FUNCTION dbo.udf_Split (@Separator char(1), @String varchar(2000))
RETURNS table
AS
RETURN (
    WITH Pieces(SplitID, start, stop) AS
    (
      SELECT 1, 1, CHARINDEX(@Separator, @String)
      UNION ALL
      SELECT SplitID + 1, stop + 1, CHARINDEX(@Separator, @String, stop + 1)
      FROM Pieces
      WHERE stop > 0
    )
    SELECT SplitID,
      SUBSTRING(@String, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS Value
    FROM Pieces
  )
0
Comment
Question by:Webboy2008
4 Comments
 
LVL 22

Expert Comment

by:Nico Bontenbal
ID: 35732227
No error here on SQL 2005. And the function seems to work also. Are you sure your SQL Server is 2005. When I run:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
I get:
9.00.5000.00      SP4      Express Edition with Advanced Services
What do you get?
0
 
LVL 9

Expert Comment

by:radcaesar
ID: 35732444
It successfully created the function in my SQL Server 2005?

What is ur DB Version?
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35735046
This should work in both SQL Server 2005 and SQL Server 2008.

If you were trying to execute this in a script, try executing this directly in a query analyzer.
0
 
LVL 21

Accepted Solution

by:
Alpesh Patel earned 2000 total points
ID: 35735613
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question