2017-02-23 63 views
0

我在下面的存儲過程中有這些錯誤。Sql存儲過程與1聲明值,2更新語句和1插入語句

當未通過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 [email protected] 

     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 
+1

和whts你這裏概率? – user7417866

+0

我有這些錯誤。 當子查詢未與EXISTS一起引入時,只能在選擇列表中指定一個表達式。 提供的值的列名或數量與表定義不匹配。 – Erebus

+0

我無法運行這個SQL過程。 – Erebus

回答

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 [email protected] 

     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