SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
alter Proc usp_GetSectionMO_TEST(@FDate varchar(30)='',@Section varchar(30)='',@StyleNo varchar(30)='',@Type varchar(30)='')
as
begin
if isnull(@FDate,'')='' select @FDate='2013-04-29'
if isnull(@Section,'')='' select @Section='A'
if isnull(@StyleNo,'')='' select @StyleNo=''
if isnull(@Type,'')='' select @Type=''
Create Table #Re_Table(
T1_MO_Code VARCHAR(16) NULL,
T1_HK_MO_Code VARCHAR(16) NULL,
T1_FDate VARCHAR(10) NULL,
T1_Style_NO VARCHAR(16) NULL,
T1_Color VARCHAR(26) NULL,
T1_Customer VARCHAR(30) NULL,
T1_Group_No VARCHAR(10) NULL,
T1_CurCode VARCHAR(10) NULL,
T1_LongNameUp NVARCHAR(255) NULL,
T1_PageNo INT NULL,
T1_Remark NVARCHAR(100) NULL,
T1_RS INT NULL,
T1_isQj INT NULL,
T1_G_kgts FLOAT NULL,
T1_isKG INT NULL,
T1_isCW INT NULL,
T1_isZG INT NULL,
T1_RS_T INT NULL,
T1_isQj_T INT NULL,
T1_G_kgts_T FLOAT NULL,
T1_isKG_T INT NULL,
T1_isCW_T INT NULL,
T1_isZG_T INT NULL,
T1_RS_A INT NULL,
T1_isQj_A INT NULL,
T1_G_kgts_A FLOAT NULL,
T1_isKG_A INT NULL,
T1_isCW_A INT NULL,
T1_isZG_A INT NULL,
T2_MO_Code VARCHAR(16) NULL,
T2_HK_MO_Code VARCHAR(16) NULL,
T2_FDate VARCHAR(10) NULL,
T2_Style_NO VARCHAR(16) NULL,
T2_Color VARCHAR(26) NULL,
T2_Customer VARCHAR(30) NULL,
T2_Group_No VARCHAR(10) NULL,
T2_CurCode VARCHAR(10) NULL,
T2_LongNameUp NVARCHAR(255) NULL,
T2_PageNo INT NULL,
T2_Remark NVARCHAR(100) NULL,
T2_RS INT NULL,
T2_isQj INT NULL,
T2_G_kgts FLOAT NULL,
T2_isKG INT NULL,
T2_isCW INT NULL,
T2_isZG INT NULL,
T2_RS_T INT NULL,
T2_isQj_T INT NULL,
T2_G_kgts_T FLOAT NULL,
T2_isKG_T INT NULL,
T2_isCW_T INT NULL,
T2_isZG_T INT NULL,
T2_RS_A INT NULL,
T2_isQj_A INT NULL,
T2_G_kgts_A FLOAT NULL,
T2_isKG_A INT NULL,
T2_isCW_A INT NULL,
T2_isZG_A INT NULL,
T3_MO_Code VARCHAR(16) NULL,
T3_HK_MO_Code VARCHAR(16) NULL,
T3_FDate VARCHAR(10) NULL,
T3_Style_NO VARCHAR(16) NULL,
T3_Color VARCHAR(26) NULL,
T3_Customer VARCHAR(30) NULL,
T3_Group_No VARCHAR(10) NULL,
T3_CurCode VARCHAR(10) NULL,
T3_LongNameUp NVARCHAR(255) NULL,
T3_PageNo INT NULL,
T3_Remark NVARCHAR(100) NULL,
T3_RS INT NULL,
T3_isQj INT NULL,
T3_G_kgts FLOAT NULL,
T3_isKG INT NULL,
T3_isCW INT NULL,
T3_isZG INT NULL,
T3_RS_T INT NULL,
T3_isQj_T INT NULL,
T3_G_kgts_T FLOAT NULL,
T3_isKG_T INT NULL,
T3_isCW_T INT NULL,
T3_isZG_T INT NULL,
T3_RS_A INT NULL,
T3_isQj_A INT NULL,
T3_G_kgts_A FLOAT NULL,
T3_isKG_A INT NULL,
T3_isCW_A INT NULL,
T3_isZG_A INT NULL,
T4_MO_Code VARCHAR(16) NULL,
T4_HK_MO_Code VARCHAR(16) NULL,
T4_FDate VARCHAR(10) NULL,
T4_Style_NO VARCHAR(16) NULL,
T4_Color VARCHAR(26) NULL,
T4_Customer VARCHAR(30) NULL,
T4_Group_No VARCHAR(10) NULL,
T4_CurCode VARCHAR(10) NULL,
T4_LongNameUp NVARCHAR(255) NULL,
T4_PageNo INT NULL,
T4_Remark NVARCHAR(100) NULL,
T4_RS INT NULL,
T4_isQj INT NULL,
T4_G_kgts FLOAT NULL,
T4_isKG INT NULL,
T4_isCW INT NULL,
T4_isZG INT NULL,
T4_RS_T INT NULL,
T4_isQj_T INT NULL,
T4_G_kgts_T FLOAT NULL,
T4_isKG_T INT NULL,
T4_isCW_T INT NULL,
T4_isZG_T INT NULL,
T4_RS_A INT NULL,
T4_isQj_A INT NULL,
T4_G_kgts_A FLOAT NULL,
T4_isKG_A INT NULL,
T4_isCW_A INT NULL,
T4_isZG_A INT NULL
)
declare cur_Brith cursor scroll for
select substring(curcode,2,2)%4 as Team,'' as MO_Code, '' as HK_MO_Code,a.FDate as TFDate, a.Style_NO as Style_NO ,a.Color AS Color,a.Customer as Customer,a.Group_NO as Group_No,CurCode as CurCode,LongNameUp as LongNameUp,PageNo as PageNo,Remark as Remark
,RS as RS,isQj AS isQj,G_kgts as G_kgts,isKG AS isKG,isCW as isCW,isZG AS isZG
, RS_T AS RS_T,isQj_T AS isQj_T, G_kgts_T AS G_kgts_T,isKG_T AS isKG_T, isCW_T AS isCW_T, isZG_T AS isZG_T
, RS_A AS RS_A, isQj_A AS isQj_A, G_kgts_A AS G_kgts_A,isKG_A as isKG_A,isCW_A as isCW_A,isZG_A AS isZG_A from T_SectionMO a
where FDate=@FDate and Group_NO like @Section+'%'
and a.Style_No like '%'+@StyleNo+'%'
open cur_Brith
declare @Team VARCHAR(10)
declare @MO_Code VARCHAR(16)
declare @HK_MO_Code VARCHAR(16)
declare @TFDate VARCHAR(10)
declare @Style_NO VARCHAR(16)
declare @Color VARCHAR(26)
declare @Customer VARCHAR(30)
declare @Group_No VARCHAR(10)
declare @CurCode VARCHAR(10)
declare @LongNameUp NVARCHAR(225)
declare @PageNo INT
declare @Remark NVARCHAR(100)
declare @RS INT
declare @isQj INT
declare @G_kgts FLOAT
declare @isKG INT
declare @isCW INT
declare @isZG INT
declare @RS_T INT
declare @isQj_T INT
declare @G_kgts_T FLOAT
declare @isKG_T INT
declare @isCW_T INT
declare @isZG_T INT
declare @RS_A INT
declare @isQj_A INT
declare @G_kgts_A FLOAT
declare @isKG_A INT
declare @isCW_A INT
declare @isZG_A INT
FETCH NEXT from cur_Brith into @Team,@MO_Code,@HK_MO_Code,@TFDate,@Style_NO,@Color,@Customer,@Group_No,@LongNameUp,@PageNo,@Remark,@RS,@isQj,@G_kgts,@isKG,@isCW,@isZG,@RS_T,@isQj_T,@G_kgts_T,@isKG_T,@isCW_T,@isZG_T,@RS_A,@isQj_A,@G_kgts_A,@isKG_A,@isCW_A,@isZG_A
WHILE @@FETCH_STATUS = 0
begin
WHILE @Team = 0
BEGIN
insert #Re_Table (T1_Group_No) values (@Group_No)
/*insert #Re_Table (T1_MO_Code ,T1_HK_MO_Code,T1_FDate,T1_Style_NO,T1_Color,T1_Customer,T1_Group_No,T1_CurCode,T1_LongNameUp,T1_PageNo,T1_Remark,T1_RS,T1_isQj,T1_G_kgts,T1_isKG,T1_isCW,T1_isZG,T1_RS_T,T1_isQj_T,T1_G_kgts_T,T1_isKG_T,T1_isCW_T,T1_isZG_T,T1_RS_A ,T1_isQj_A ,T1_G_kgts_A ,T1_isKG_A ,T1_isCW_A ,T1_isZG_A ) values(@MO_Code,@HK_MO_Code,@TFDate,@Style_NO,@Color,@Customer,@Group_No,replace(@LongNameUp,'?',N'组'),@PageNo,@Remark,@RS,@isQj,@G_kgts,@isKG,@isCW,@isZG,@RS_T,@isQj_T,@G_kgts_T,@isKG_T,@isCW_T,@isZG_T,@RS_A,@isQj_A,@G_kgts_A,@isKG_A,@isCW_A,@isZG_A) */
END
FETCH NEXT from cur_Brith into @Team,@MO_Code,@HK_MO_Code,@TFDate,@Style_NO,@Color,@Customer,@Group_No,@LongNameUp,@PageNo,@Remark,@RS,@isQj,@G_kgts,@isKG,@isCW,@isZG,@RS_T,@isQj_T,@G_kgts_T,@isKG_T,@isCW_T,@isZG_T,@RS_A,@isQj_A,@G_kgts_A,@isKG_A,@isCW_A,@isZG_A
end
close cur_Brith
deallocate cur_Brith
SELECT * FROM #Re_Table
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
EXEC usp_GetSectionMO_TEST
各位大俠幫我看看 是哪裡語法出問題了
------解决思路----------------------
我估计是:
Cursorfetch: INTO 列表中声明的变量数目必须与所选列的数目相同。
你看看你select 到游标中的列和into到变量的数目是否一致。
------解决思路----------------------
declare cur_Brith cursor scroll for
select substring(curcode,2,2)%4 as Team,'' as MO_Code, '' as HK_MO_Code,a.FDate as TFDate, a.Style_NO as Style_NO ,
a.Color AS Color,a.Customer as Customer,a.Group_NO as Group_No,CurCode as CurCode,LongNameUp as LongNameUp,PageNo as PageNo,Remark as Remark --这一行
,RS as RS,isQj AS isQj,G_kgts as G_kgts,isKG AS isKG,isCW as isCW,isZG AS isZG
, RS_T AS RS_T,isQj_T AS isQj_T, G_kgts_T AS G_kgts_T,isKG_T AS isKG_T, isCW_T AS isCW_T, isZG_T AS isZG_T
, RS_A AS RS_A, isQj_A AS isQj_A, G_kgts_A AS G_kgts_A,isKG_A as isKG_A,isCW_A as isCW_A,isZG_A AS isZG_A from T_SectionMO a
和
FETCH NEXT from cur_Brith into @Team,@MO_Code,@HK_MO_Code,@TFDate,@Style_NO,
@Color,@Customer,@Group_No,@LongNameUp,@PageNo,@Remark, --这一行
@RS,@isQj,@G_kgts,@isKG,@isCW,@isZG,@RS_T,@isQj_T,@G_kgts_T,@isKG_T,@isCW_T,@isZG_T,@RS_A,@isQj_A,@G_kgts_A,@isKG_A,@isCW_A,@isZG_A
里面的字段不对应
------解决思路----------------------
查询的列与表的列不匹配,不如表有一列,你查询两列插入,肯定有问题阿