我在下面的存储过程中遇到这些错误。
当选择列表中只能指定一个表达式时 EXISTS不引入子查询。列名或数字 提供的值与表定义不匹配。
Create PROCEDURE [dbo].[tbl_TeleCom_UpdateTeleComNo]
@type varchar(100) ,
@comNo varchar(100),
@status bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @b_ComNo varchar(100)
Set @b_ComNo = (Select * from tbl_TeleCom where Type = @type)
IF @b_ComNo IS NOT NULL
BEGIN
Insert Into tbl_ComNoHistory
Select B_ComNo, B_StartTime, B_EndTime
from tbl_TeleCom
where Type = @type
Group By B_ComNo, B_StartTime, B_EndTime
END
Update tbl_Balance Set
Status = 0
from tbl_Balance
Join tbl_TeleCom On tbl_TeleCom.CurrentComNo = tbl_Balance.ComNo
And tbl_TeleCom.Type = @type
Update tbl_TeleCom Set
CurrentComNo = @comNo,
CurrentTime = GETDATE(),
B_ComNo = CurrentComNo,
B_StartTime = CurrentTime,
B_EndTime = GETDATE()
where Type =@type
Update tbl_Balance Set
Status = @status
from tbl_Balance
Join tbl_TeleCom On tbl_TeleCom.CurrentComNo = tbl_Balance.ComNo
And tbl_TeleCom.Type = @type
END
答案 0 :(得分:0)
Create PROCEDURE [dbo].[tbl_TeleCom_UpdateTeleComNo]
@type varchar(100) ,
@comNo varchar(100),
@status bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @b_ComNo varchar(100)
SELECT @b_ComNo = ComNo from tbl_TeleCom where Type = @type
IF @b_ComNo IS NOT NULL
BEGIN
Insert Into tbl_ComNoHistory
Select B_ComNo, B_StartTime, B_EndTime
from tbl_TeleCom
where Type = @type
Group By B_ComNo, B_StartTime, B_EndTime
END
Update tbl_Balance Set
Status = 0
from tbl_Balance
Join tbl_TeleCom On tbl_TeleCom.CurrentComNo = tbl_Balance.ComNo
And tbl_TeleCom.Type = @type
Update tbl_TeleCom Set
CurrentComNo = @comNo,
CurrentTime = GETDATE(),
B_ComNo = CurrentComNo,
B_StartTime = CurrentTime,
B_EndTime = GETDATE()
where Type =@type
Update tbl_Balance Set
Status = @status
from tbl_Balance
Join tbl_TeleCom On tbl_TeleCom.CurrentComNo = tbl_Balance.ComNo
And tbl_TeleCom.Type = @type
END