我的"建立存储过程"的代码如下,出错信息附后,请帮助看下有什么毛病?set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>@d1 datetime
-- =============================================
create FUNCTION [dbo].[tmd2](@d1 datetime)
Returns @ctable TABLE (
[区号] [nchar](10) NULL,
[安装户数] [numeric](38, 2) NOT NULL,
[恢复户数] [numeric](38, 2) NOT NULL,
[报停户数] [numeric](38, 2) NOT NULL,
[撤线户数] [numeric](38, 2) NOT NULL,
[作废户数] [numeric](38, 2) NOT NULL
)
AS
BEGIN
Insert @ctable
select bm.区号,isnull(安装户数,0) 安装户数,isnull(迁入户数,0) 迁入户数,isnull(恢复户数,0) 恢复户数,isnull(迁出户数,0) 迁出户数,isnull(报停户数,0) 报停户数isnull(撤线户数,0) 撤线户数,isnull(作废户数,0) 作废户数 from (select distinct 区号 from zk) bm
left JOIN (select 区号,count(*) as 安装户数 from zk where 初装日期 <=@d1 group by 区号) zk on bm.区号=zk.区号
left JOIN (select 区号,count(*) as 恢复户数 from hf join zk on hf.证号=zk.证号 and hf.终端号=zk.终端号 where 恢复时间 <=@d1 group by 区号) hf on bm.区号=hf.区号
left JOIN (select 区号,count(*) as 报停户数 from bt join zk on bt.证号=zk.证号 and bt.终端号=zk.终端号 where 报停时间 <=@d1 group by 区号) bt on bm.区号=bt.区号
left JOIN (select 区号,count(*) as 撤线户数 from cx join zk on cx.证号=zk.证号 and cx.终端号=zk.终端号 where 撤线时间 <=@d1 group by 区号) cx on bm.区号=cx.区号
left JOIN (select 区号,count(*) as 作废户数 from zf join zk on zf.证号=zk.证号 and zf.终端号=zk.终端号 where 作废时间 <=@d1 group by 区号) hf on bm.区号=zf.区号
RETURN
END
出错星系如下:
消息 102,级别 15,状态 1,过程 tmd2,第 18 行
'撤线户数' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 18 行
'bm' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 19 行
'zk' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 20 行
'hf' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 21 行
'bt' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 22 行
'cx' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 23 行
'hf' 附近有语法错误。
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>@d1 datetime
-- =============================================
create FUNCTION [dbo].[tmd2](@d1 datetime)
Returns @ctable TABLE (
[区号] [nchar](10) NULL,
[安装户数] [numeric](38, 2) NOT NULL,
[恢复户数] [numeric](38, 2) NOT NULL,
[报停户数] [numeric](38, 2) NOT NULL,
[撤线户数] [numeric](38, 2) NOT NULL,
[作废户数] [numeric](38, 2) NOT NULL
)
AS
BEGIN
Insert @ctable
select bm.区号,isnull(安装户数,0) 安装户数,isnull(迁入户数,0) 迁入户数,isnull(恢复户数,0) 恢复户数,isnull(迁出户数,0) 迁出户数,isnull(报停户数,0) 报停户数isnull(撤线户数,0) 撤线户数,isnull(作废户数,0) 作废户数 from (select distinct 区号 from zk) bm
left JOIN (select 区号,count(*) as 安装户数 from zk where 初装日期 <=@d1 group by 区号) zk on bm.区号=zk.区号
left JOIN (select 区号,count(*) as 恢复户数 from hf join zk on hf.证号=zk.证号 and hf.终端号=zk.终端号 where 恢复时间 <=@d1 group by 区号) hf on bm.区号=hf.区号
left JOIN (select 区号,count(*) as 报停户数 from bt join zk on bt.证号=zk.证号 and bt.终端号=zk.终端号 where 报停时间 <=@d1 group by 区号) bt on bm.区号=bt.区号
left JOIN (select 区号,count(*) as 撤线户数 from cx join zk on cx.证号=zk.证号 and cx.终端号=zk.终端号 where 撤线时间 <=@d1 group by 区号) cx on bm.区号=cx.区号
left JOIN (select 区号,count(*) as 作废户数 from zf join zk on zf.证号=zk.证号 and zf.终端号=zk.终端号 where 作废时间 <=@d1 group by 区号) hf on bm.区号=zf.区号
RETURN
END
出错星系如下:
消息 102,级别 15,状态 1,过程 tmd2,第 18 行
'撤线户数' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 18 行
'bm' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 19 行
'zk' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 20 行
'hf' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 21 行
'bt' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 22 行
'cx' 附近有语法错误。
消息 102,级别 15,状态 1,过程 tmd2,第 23 行
'hf' 附近有语法错误。
create FUNCTION [dbo].[tmd2](@d1 datetime)
Returns @ctable TABLE (
[区号] [nchar](10) NULL,
[安装户数] [numeric](38, 2) NOT NULL,
[恢复户数] [numeric](38, 2) NOT NULL,
[报停户数] [numeric](38, 2) NOT NULL,
[撤线户数] [numeric](38, 2) NOT NULL,
[作废户数] [numeric](38, 2) NOT NULL
)
AS
BEGIN
Insert @ctable
select bm.区号,isnull(安装户数,0) 安装户数,isnull(迁入户数,0) 迁入户数
,isnull(恢复户数,0) 恢复户数
,isnull(迁出户数,0) 迁出户数,isnull(报停户数,0) 报停户数,isnull(撤线户数,0) 撤线户数,isnull(作废户数,0) 作废户数 from (select distinct 区号 from zk) bm
left JOIN (select 区号,count(*) as 安装户数 from zk where 初装日期 <=@d1 group by 区号) zk on bm.区号=zk.区号
left JOIN (select 区号,count(*) as 恢复户数 from hf join zk on hf.证号=zk.证号 and hf.终端号=zk.终端号 where 恢复时间 <=@d1 group by 区号) hf on bm.区号=hf.区号
left JOIN (select 区号,count(*) as 报停户数 from bt join zk on bt.证号=zk.证号 and bt.终端号=zk.终端号 where 报停时间 <=@d1 group by 区号) bt on bm.区号=bt.区号
left JOIN (select 区号,count(*) as 撤线户数 from cx join zk on cx.证号=zk.证号 and cx.终端号=zk.终端号 where 撤线时间 <=@d1 group by 区号) cx on bm.区号=cx.区号
left JOIN (select 区号,count(*) as 作废户数 from zf join zk on zf.证号=zk.证号 and zf.终端号=zk.终端号 where 作废时间 <=@d1 group by 区号) hf on bm.区号=zf.区号
RETURN
END
少了一个逗号,给你加上了
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>@d1 datetime
-- =============================================
create FUNCTION [dbo].[tmd2](@d1 datetime)
Returns @ctable TABLE (
[区号] [nchar](10) NULL,
[安装户数] [numeric](38, 2) NOT NULL,
[恢复户数] [numeric](38, 2) NOT NULL,
[报停户数] [numeric](38, 2) NOT NULL,
[撤线户数] [numeric](38, 2) NOT NULL,
[作废户数] [numeric](38, 2) NOT NULL
)
AS
BEGIN
Insert @ctable
select bm.区号,
isnull(安装户数,0) '安装户数',
isnull(迁入户数,0) '迁入户数',
isnull(恢复户数,0) '恢复户数',
isnull(迁出户数,0) '迁出户数',
isnull(报停户数,0) '报停户数',
isnull(撤线户数,0) '撤线户数',
isnull(作废户数,0) '作废户数'
from (select distinct 区号 from zk) bm
left JOIN (select 区号,count(*) as 安装户数 from zk
left JOIN (select 区号,count(*) as 恢复户数 from hf join zk on hf.证号=zk.证号 and hf.终端号=zk.终端号 where 恢复时间 <=@d1 group by 区号) hf on bm.区号=hf.区号
left JOIN (select 区号,count(*) as 报停户数 from bt join zk on bt.证号=zk.证号 and bt.终端号=zk.终端号 where 报停时间 <=@d1 group by 区号) bt on bm.区号=bt.区号
left JOIN (select 区号,count(*) as 撤线户数 from cx join zk on cx.证号=zk.证号 and cx.终端号=zk.终端号 where 撤线时间 <=@d1 group by 区号) cx on bm.区号=cx.区号
left JOIN (select 区号,count(*) as 作废户数 from zf join zk on zf.证号=zk.证号 and zf.终端号=zk.终端号 where 作废时间 <=@d1 group by 区号) hf on bm.区号=zf.区号
where 初装日期 <=@d1 group by 区号) zk on bm.区号=zk.区号
RETURN
END
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>@d1 datetime
-- =============================================
create FUNCTION [dbo].[tmd2](@d1 datetime)
Returns @ctable TABLE (
[区号] [nchar](10) NULL,
[安装户数] [numeric](38, 2) NOT NULL,
[恢复户数] [numeric](38, 2) NOT NULL,
[报停户数] [numeric](38, 2) NOT NULL,
[撤线户数] [numeric](38, 2) NOT NULL,
[作废户数] [numeric](38, 2) NOT NULL
)
AS
BEGIN
Insert @ctable
select bm.区号,isnull(安装户数,0) 安装户数,isnull(迁入户数,0) 迁入户数,isnull(恢复户数,0) 恢复户数,isnull(迁出户数,0) 迁出户数,isnull(报停户数,0) 报停户数,isnull(撤线户数,0) 撤线户数,isnull(作废户数,0) 作废户数 from (select distinct 区号 from zk) bm
left JOIN (select 区号,count(*) as 安装户数 from zk where 初装日期 <=@d1 group by 区号) zk on bm.区号=zk.区号
left JOIN (select 区号,count(*) as 恢复户数 from hf join zk on hf.证号=zk.证号 and hf.终端号=zk.终端号 and 恢复时间 <=@d1 group by 区号) hf on bm.区号=hf.区号
left JOIN (select 区号,count(*) as 报停户数 from bt join zk on bt.证号=zk.证号 and bt.终端号=zk.终端号 and 报停时间 <=@d1 group by 区号) bt on bm.区号=bt.区号
left JOIN (select 区号,count(*) as 撤线户数 from cx join zk on cx.证号=zk.证号 and cx.终端号=zk.终端号 and 撤线时间 <=@d1 group by 区号) cx on bm.区号=cx.区号
left JOIN (select 区号,count(*) as 作废户数 from zf join zk on zf.证号=zk.证号 and zf.终端号=zk.终端号 and 作废时间 <=@d1 group by 区号) hf on bm.区号=zf.区号
RETURN
END
BEGIN
Insert @ctable
select bm.区号,isnull(安装户数,0) 安装户数,isnull(迁入户数,0) 迁入户数,isnull(恢复户数,0) 恢复户
好像少了個 ',' ,可以添加后再試試看.其他的問題看是否和其相關。