使用函数在SQL查询中获取错误

时间:2021-12-29 14:55:56

When I run this query through C# adapter it is causing an error:

当我通过c#适配器运行这个查询时,它会导致一个错误:

Incorrect syntax near Use

不正确的语法使用附近

Any ideas? When I run this in SQL Server 2008 R2 it's working fine.

什么好主意吗?当我在SQL Server 2008 R2中运行它时,它运行得很好。

create FUNCTION [dbo].[fn_Split] (@sep nvarchar(10), @s nvarchar(4000))
RETURNS table
AS
  RETURN (
  WITH Pieces(pn, start, stop) AS (
  SELECT 1, 1, CHARINDEX(@sep, @s)
  UNION ALL
  SELECT pn + 1, stop + (datalength(@sep)/2), 
    CHARINDEX(@sep, @s, stop + (datalength(@sep)/2))
  FROM Pieces
  WHERE stop > 0
)
SELECT pn,
SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 4000 END) AS value
FROM Pieces
)
;

/****** Object: Table [dbo].[drillDowntable1] Script Date: 09/24/2012 18:43:32 ******/
USE [master]

SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
SET ANSI_PADDING ON
;
CREATE TABLE [dbo].[drillDowntable1](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](20) NULL,
[json] [varchar](max) NULL,
[isActive] [bit] NOT NULL
) ON [PRIMARY]

1 个解决方案

#1


5  

You need a GO to put things in their own batch.

你需要去把东西放到他们自己的批次里。

FROM Pieces
)
;

GO -- < this is important
/****** Object: Table [dbo].[drillDowntable1] Script Date: 09/24/2012 18:43:32 ******/
USE [master]

#1


5  

You need a GO to put things in their own batch.

你需要去把东西放到他们自己的批次里。

FROM Pieces
)
;

GO -- < this is important
/****** Object: Table [dbo].[drillDowntable1] Script Date: 09/24/2012 18:43:32 ******/
USE [master]