pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

無法在變量中獲取存儲過程的結果?

Not able to get the stored procedure#39;s result in variable?(無法在變量中獲取存儲過程的結果?)
本文介紹了無法在變量中獲取存儲過程的結果?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個存儲過程的層次結構,如下所示:

i have a Hierarchy of stored procedures calling one in another as below:

1
 2
  3

現在我正在做的是:首先,我展示的是最低級別的第 3 級 sp.

Now what i am doing is: first of all i am showing the 3rd level sp which is least level.

CREATE proc [dbo].[proc_tblUserScheduleNewUpdateOnly] 
(      
@Scheduleid bigint=258,                            
@Contactid uniqueidentifier='EDE3E474-02CA-49C7-86DD-AA97794ECF8A',                                     
@ScheduleDate datetime= '2012-07-16 00:00:00.000',                                    
@StartTime varchar(20)='12:03:00.0000000',                                    
@EndTime varchar(20)='15:00:00.0000000',                                    
@Location bigint=8,                                    
@Area bigint=7,                                    
@Room bigint=9,                        
@Enddate datetime='2012-07-16 00:00:00.000',                    
@CurrentTime Datetime='2012-07-16 12:00:35.900',      
@ModifiedBy uniqueidentifier='0BF84A77-FAC2-44E5-AF9B-39740415DBD2',                  
@schedulefileidNew bigint=''         
)      
as      
Declare @schedulefileid bigint      
if @schedulefileidNew=0                
 begin                
   set @schedulefileid=null                
 end                
else                
 begin                
set @schedulefileid=@schedulefileidNew                
end       
update tblUserScheduleNew   set Contactid=@Contactid,      
ScheduleDate =@ScheduleDate,      
StartTime = @StartTime,      
EndTime =@EndTime,      
Location =@Location,      
Area=@Area,      
Room =@Room,      
LastModifiedDate=@CurrentTime ,EndDate=@Enddate,      
ModifiedBy=@ModifiedBy,      
ScheduleFileId=@schedulefileid      
where ScheduleId=@Scheduleid and IsDeleted=0 and isActive=1      
select 1  

現在是第二級:

CREATE Proc [dbo].[proc_tblUserScheduleNewFutureUpdate]
(          
@StartDatePassed datetime='8/2/2012 12:00:00 AM',       
@EndDatePassed datetime='8/2/2012 12:00:00 AM', --='2012-07-11 00:00:00.000',          
@StartTimePassed varchar(20)='13:00:00',--='02:00:00.0000000',          
@EndTimePassed varchar(20)='21:00:00',--='03:00:00.0000000',          
@CurrentDateTime Datetime ='8/1/2012 5:50:31 AM', --='2012-07-11 02:07:35.900'          
@Scheduleid bigint=0x0000000000000166,          
@Contactid uniqueidentifier='77680636-bc4b-4489-9cec-3bc000ffe773',          
@Location bigint=11,          
@Area bigint=10,          
@Room bigint=11,          
@ModifiedBy uniqueidentifier='acf7961c-4111-49ad-a66a-ce7f9ce131bd',          
@schedulefileidNew bigint=null         
)          
as  
declare @ResultForInsertUpdate varchar(200);  
if CONVERT(date,@StartDatePassed,101)>CONVERT(date,@CurrentDateTime,101) and     
CONVERT(date,@EndDatePassed,101)>CONVERT(date,@CurrentDateTime,101) and
 CONVERT(date,@EndDatePassed,101)>CONVERT(date,@StartDatePassed,101)           
  begin -- it will run when the Start date and end date passed are greater than Current date and EndDate is greater than Start date.          
Print 'Update'          
exec @ResultForInsertUpdate =  dbo.proc_tblUserScheduleNewUpdateOnly @Scheduleid,@Contactid,@StartDatePassed,@StartTimePassed,@EndTimePassed,@Location,@Area,@Room,@EndDatePassed,@CurrentDateTime,@ModifiedBy,@schedulefileidNew          
select @ResultForInsertUpdate;  
  end          
else
begin
select 2
end

現在是第 3 級和最后一級

Now the 3rd and final level

Alter Proc proc_tblUserScheduleNewUpdateWithAllRoomsOption
(
@StartDatePassed datetime='2013-04-29 00:00:00.000',
@EndDatePassed datetime='2013-04-29 00:00:00.000',
@StartTimePassed varchar(20)='15:00:00',
@EndTimePassed varchar(20)='20:00:00',
@CurrentDateTime Datetime ='2013-04-25 00:00:00.000',
@Scheduleid bigint=1,
@Contactid uniqueidentifier='FD3E0DDF-8B91-493F-94DF-B8280AC33BC0',
@Location bigint=17,
@Area bigint=0,
@Room bigint=0,
@ModifiedBy uniqueidentifier='ACF7961C-4111-49AD-A66A-CE7F9CE131BD',
@schedulefileidNew bigint=null,
@OldStartDate Datetime='2013-04-26 00:00:00.000',
@OldEndDate DateTime='2013-04-26 00:00:00.000',
@OldStartTime varchar(20)='11:11:11.0000000',
@OldEndTime varchar(20)='22:22:22.0000000',
@OldContactid uniqueidentifier='DA101C1D-45A1-4F9A-B19B-4E88DDE01B10',
@OldLocation bigint=18,
@OldArea bigint=17,
@OldRoom bigint=22
)
as
-- declare variables Starts here       
declare @row_count int;        
DECLARE @intFlag INT=0;      
declare @locationIdForLoop bigint  ;      
declare @AreaIdForLoop bigint  ;      
declare @RoomIdForLoop bigint  ;   
DECLARE @ResultForInsertUpdate INT      
set @ResultForInsertUpdate=1;
-- declare tempraroy table to store location, Area and rooms Starts here      
CREATE TABLE  #tempTable (      
RowNum int,        
LocationId bigint,
AreaId bigint,
RoomId bigint
)
-- declare tempraroy table to store location, Area and rooms Ends here
if @Area=0 and @Room=0
begin
insert into #tempTable (RowNum,LocationId,AreaId,RoomId) (select ROW_NUMBER() OVER 
(ORDER BY LocationId desc) RowNum, LocationId,AreaId,RoomId from
tblroomnew where areaid in(select Areaid from tblareanew where locationid=@Location))
set @row_count=(select count(*) from #tempTable)
SET @intFlag = 1
WHILE (@intFlag <=@row_count)
BEGIN
-- Do what ever you want to do here
set @locationIdForLoop=(select locationid from #tempTable where RowNum=@intFlag)
set @AreaIdForLoop=(select areaid from #tempTable where RowNum=@intFlag)
set @RoomIdForLoop=(select roomid from #tempTable where RowNum=@intFlag)
if @ResultForInsertUpdate=1
begin
if exists(select 1 from tbluserschedulenew where 
convert(datetime,ScheduleDate,101)=convert(datetime,@OldStartDate,101) and
Convert(datetime,EndDate,101)=convert(datetime,@OldEndDate,101) and 
convert(Time,StartTime,108)=convert(Time,@OldStartTime,108) and
convert(Time,EndTime,108) =convert(Time,@OldEndTime,108) and contactid=@OldContactid 
and
Location=@OldLocation and Area=@OldArea and Room=@OldRoom )
begin
Print 'Update First record'
exec @ResultForInsertUpdate = proc_tblUserScheduleNewFutureUpdate @StartDatePassed,@EndDatePassed,@StartTimePassed,@EndTimePassed,@CurrentDateTime,@Scheduleid,@Contactid,
@locationIdForLoop,@AreaIdForLoop,@RoomIdForLoop,@ModifiedBy,@schedulefileidNew
--set @ResultForInsertUpdate=1
print @ResultForInsertUpdate
--select @ResultForInsertUpdate
end
else
begin
print 'insert karna hai record'
exec  proc_tblUserScheduleNewLatestInsert @Contactid,@StartDatePassed,@StartTimePassed,@EndTimePassed,
@locationIdForLoop,@AreaIdForLoop,@RoomIdForLoop, @EndDatePassed,@ModifiedBy,0,@CurrentDateTime
--print @ResultForInsertUpdate
end
end
else
begin
select @ResultForInsertUpdate
end
SET @intFlag = @intFlag + 1
END
end
else
begin
if @Area!=0 and @Room=0
begin
insert into #tempTable (RowNum,LocationId,AreaId,RoomId) (select ROW_NUMBER() OVER (ORDER BY LocationId desc) RowNum, LocationId,AreaId,RoomId from
tblroomnew where areaid =@Area)
set @row_count=(select count(*) from #tempTable)
end
else
begin
print 'chalan do jo chal reha'
exec proc_tblUserScheduleNewFutureUpdate @StartDatePassed,@EndDatePassed,@StartTimePassed,@EndTimePassed,@CurrentDateTime,@Scheduleid,@Contactid,
 @location,@Area,@Room,@ModifiedBy,@schedulefileidNew
--print 'simple update'
end
end

現在我的問題是什么:

我選擇 1 作為第三級的結果,它將存儲在第二級的@ResultForInsertUpdate"中,然后再次存儲在第三級..

I am selecting 1 as result in 3rd level which will stored in "@ResultForInsertUpdate" in second level and in 3rd level again..

我在@ResultForInsertUpdate 中得到 0 我不知道為什么,請幫我解決這個問題

I am getting 0 in @ResultForInsertUpdate i dont know why, please help me to resolve this prob

推薦答案

也許這對你有幫助 -

Possible this be helpful for you -

1.

CREATE PROCEDURE [dbo].[proc_tblUserScheduleNewUpdateOnly]
(
      @Scheduleid BIGINT
    , @Contactid UNIQUEIDENTIFIER
    , @ScheduleDate DATETIME
    , @StartTime VARCHAR(20)
    , @EndTime VARCHAR(20)
    , @Location BIGINT
    , @Area BIGINT
    , @Room BIGINT
    , @Enddate DATETIME
    , @CurrentTime DATETIME
    , @ModifiedBy UNIQUEIDENTIFIER
    , @schedulefileidNew BIGINT
)
AS BEGIN

    UPDATE dbo.tblUserScheduleNew
    SET     
          Contactid = @Contactid 
        , ScheduleDate = @ScheduleDate 
        , StartTime = @StartTime 
        , EndTime = @EndTime 
        , location = @Location 
        , Area = @Area 
        , Room = @Room 
        , LastModifiedDate = @CurrentTime 
        , EndDate = @Enddate 
        , ModifiedBy = @ModifiedBy 
        , ScheduleFileId = NULLIF(@schedulefileidNew, 0)
    WHERE ScheduleID = @Scheduleid 
        AND IsDeleted = 0
        AND isActive = 1

    RETURN 1

END

2.

CREATE PROCEDURE [dbo].[proc_tblUserScheduleNewFutureUpdate] 
(
      @StartDatePassed DATETIME
    , @EndDatePassed DATETIME
    , @StartTimePassed VARCHAR(20)
    , @EndTimePassed VARCHAR(20)
    , @CurrentDateTime DATETIME
    , @Scheduleid BIGINT
    , @Contactid UNIQUEIDENTIFIER
    , @Location BIGINT
    , @Area BIGINT
    , @Room BIGINT
    , @ModifiedBy UNIQUEIDENTIFIER
    , @schedulefileidNew BIGINT
)
AS BEGIN

    IF 
          CONVERT(DATE, @StartDatePassed, 101) > CONVERT(DATE, @CurrentDateTime, 101) 
        AND
          CONVERT(DATE, @EndDatePassed, 101) > CONVERT(DATE, @CurrentDateTime, 101) 
        AND
          CONVERT(DATE, @EndDatePassed, 101) > CONVERT(DATE, @StartDatePassed, 101)

    BEGIN    

        DECLARE @ResultForInsertUpdate VARCHAR(200)

        EXEC @ResultForInsertUpdate = dbo.proc_tblUserScheduleNewUpdateOnly 
                @Scheduleid
            ,   @Contactid
            ,   @StartDatePassed
            ,   @StartTimePassed
            ,   @EndTimePassed
            ,   @Location
            ,   @Area
            ,   @Room
            ,   @EndDatePassed
            ,   @CurrentDateTime
            ,   @ModifiedBy
            ,   @schedulefileidNew

        RETURN @ResultForInsertUpdate

    END
    ELSE BEGIN

        RETURN 2

    END

END

3.

CREATE PROCEDURE proc_tblUserScheduleNewUpdateWithAllRoomsOption 
(
    @StartDatePassed DATETIME,
    @EndDatePassed DATETIME,
    @StartTimePassed VARCHAR(20),
    @EndTimePassed VARCHAR(20),
    @CurrentDateTime DATETIME,
    @Scheduleid BIGINT,
    @Contactid UNIQUEIDENTIFIER,
    @Location BIGINT,
    @Area BIGINT,
    @Room BIGINT,
    @ModifiedBy UNIQUEIDENTIFIER,
    @schedulefileidNew BIGINT,
    @OldStartDate DATETIME,
    @OldEndDate DATETIME,
    @OldStartTime VARCHAR(20),
    @OldEndTime VARCHAR(20),
    @OldContactid UNIQUEIDENTIFIER,
    @OldLocation BIGINT,
    @OldArea BIGINT,
    @OldRoom BIGINT
)
AS BEGIN

    DECLARE 
          @row_count INT
        , @intFlag INT = 0
        , @locationIdForLoop BIGINT
        , @AreaIdForLoop BIGINT
        , @RoomIdForLoop BIGINT
        , @ResultForInsertUpdate INT = 1

    CREATE TABLE #tempTable (RowNum INT, LocationId BIGINT, AreaId BIGINT, RoomId BIGINT)

    IF @Area = 0 AND @Room = 0 BEGIN

        INSERT INTO #tempTable (RowNum, LocationId, AreaId, RoomId)
        SELECT
                ROW_NUMBER() OVER (ORDER BY LocationId DESC) RowNum
            ,   LocationId
            ,   AreaId
            ,   RoomId
        FROM dbo.tblroomnew a
        WHERE a.AreaId IN (
            SELECT b.AreaId
            FROM dbo.tblareanew b
            WHERE b.LocationId = @Location
        )

        SELECT 
              @row_count = COUNT(1) 
            , @intFlag = 1
        FROM #tempTable

        WHILE (@intFlag <= @row_count) BEGIN

            SELECT 
                  @locationIdForLoop = LocationId
                , @AreaIdForLoop = AreaId
                , @RoomIdForLoop = RoomId
            FROM #tempTable
            WHERE RowNum=@intFlag

            IF @ResultForInsertUpdate = 1 BEGIN
                IF EXISTS (
                    SELECT 1
                    FROM dbo.tbluserschedulenew
                    WHERE 
                        CONVERT(DATETIME,ScheduleDate,101)=CONVERT(DATETIME,@OldStartDate,101) AND
                        CONVERT(DATETIME,EndDate,101)=CONVERT(DATETIME,@OldEndDate,101) AND
                        CONVERT(TIME,StartTime,108)=CONVERT(TIME,@OldStartTime,108) AND
                        CONVERT(TIME,EndTime,108)=CONVERT(TIME,@OldEndTime,108) AND contactid=@OldContactid
                        AND location=@OldLocation 
                        AND Area=@OldArea 
                        AND Room=@OldRoom
                )
                BEGIN

                    PRINT 'Update First record'
                    EXEC @ResultForInsertUpdate=proc_tblUserScheduleNewFutureUpdate 
                            @StartDatePassed
                        ,   @EndDatePassed
                        ,   @StartTimePassed
                        ,   @EndTimePassed
                        ,   @CurrentDateTime
                        ,   @Scheduleid
                        ,   @Contactid
                        ,   @locationIdForLoop
                        ,   @AreaIdForLoop
                        ,   @RoomIdForLoop
                        ,   @ModifiedBy
                        ,   @schedulefileidNew

                    RETURN @ResultForInsertUpdate

                END
                ELSE
                BEGIN

                    EXEC proc_tblUserScheduleNewLatestInsert    
                            @Contactid
                        ,   @StartDatePassed
                        ,   @StartTimePassed
                        ,   @EndTimePassed
                        ,   @locationIdForLoop
                        ,   @AreaIdForLoop
                        ,   @RoomIdForLoop
                        ,   @EndDatePassed
                        ,   @ModifiedBy
                        ,   0
                        ,   @CurrentDateTime

                END
            END
            ELSE BEGIN

                RETURN @ResultForInsertUpdate

            END
            SELECT @intFlag = @intFlag + 1
        END
    END
    ELSE
    BEGIN
        IF @Area != 0 AND @Room = 0 BEGIN

            INSERT INTO #tempTable (RowNum, LocationId, AreaId, RoomId)
            SELECT
                    ROW_NUMBER() OVER (ORDER BY LocationId DESC) RowNum
                ,   LocationId
                ,   AreaId
                ,   RoomId
            FROM dbo.tblroomnew a

            SELECT @row_count = COUNT(1)
            FROM #tempTable

        END
        ELSE BEGIN

            EXEC dbo.proc_tblUserScheduleNewFutureUpdate 
                        @StartDatePassed
                    ,   @EndDatePassed
                    ,   @StartTimePassed
                    ,   @EndTimePassed
                    ,   @CurrentDateTime
                    ,   @Scheduleid
                    ,   @Contactid
                    ,   @location
                    ,   @Area
                    ,   @Room
                    ,   @ModifiedBy
                    ,   @schedulefileidNew
        END

    END

END

這篇關于無法在變量中獲取存儲過程的結果?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 沧州友城管业有限公司-内外涂塑钢管-大口径螺旋钢管-涂塑螺旋管-保温钢管生产厂家 | 东莞精密模具加工,精密连接器模具零件,自動機零件,冶工具加工-益久精密 | 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | MOOG伺服阀维修,ATOS比例流量阀维修,伺服阀维修-上海纽顿液压设备有限公司 | 空压机网_《压缩机》杂志 | 通辽信息港 - 免费发布房产、招聘、求职、二手、商铺等信息 www.tlxxg.net | 球形钽粉_球形钨粉_纳米粉末_难熔金属粉末-广东银纳官网 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 英国公司注册-新加坡公司注册-香港公司开户-离岸公司账户-杭州商标注册-杭州优创企业 | 深圳工程师职称评定条件及流程_深圳职称评审_职称评审-职称网 | 耙式干燥机_真空耙式干燥机厂家-无锡鹏茂化工装备有限公司 | hdpe土工膜-防渗膜-复合土工膜-长丝土工布价格-厂家直销「恒阳新材料」-山东恒阳新材料有限公司 ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | 热熔胶网膜|pes热熔网膜价格|eva热熔胶膜|热熔胶膜|tpu热熔胶膜厂家-苏州惠洋胶粘制品有限公司 | 包头市鑫枫装饰有限公司 | 火锅底料批发-串串香技术培训[川禾川调官网]| Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | Safety light curtain|Belt Sway Switches|Pull Rope Switch|ultrasonic flaw detector-Shandong Zhuoxin Machinery Co., Ltd | 岩棉板|岩棉复合板|聚氨酯夹芯板|岩棉夹芯板|彩钢夹芯板-江苏恒海钢结构 | 水厂自动化-水厂控制系统-泵站自动化|控制系统-闸门自动化控制-济南华通中控科技有限公司 | 猎头招聘_深圳猎头公司_知名猎头公司 | 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 海外仓系统|国际货代系统|退货换标系统|WMS仓储系统|海豚云 | 比亚迪叉车-比亚迪电动叉车堆垛车托盘车仓储叉车价格多少钱报价 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 英思科GTD-3000EX(美国英思科气体检测仪MX4MX6)百科-北京嘉华众信科技有限公司 | 防水接头-电缆防水接头-金属-电缆密封接头-不锈钢电缆接头 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 至顶网| 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | sus630/303cu不锈钢棒,440C/430F/17-4ph不锈钢研磨棒-江苏德镍金属科技有限公司 | 不锈钢闸阀_球阀_蝶阀_止回阀_调节阀_截止阀-可拉伐阀门(上海)有限公司 | 圆盘鞋底注塑机_连帮鞋底成型注塑机-温州天钢机械有限公司 | 香港新时代国际美容美发化妆美甲培训学校-26年培训经验,值得信赖! | 三轴曲线机-端子插拔力试验机|华杰仪器 | 杭州高温泵_热水泵_高温油泵|昆山奥兰克泵业制造有限公司 | 短信通106短信接口验证码接口群发平台_国际短信接口验证码接口群发平台-速度网络有限公司 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 液氮罐_液氮容器_自增压液氮罐_杜瓦瓶_班德液氮罐厂家 |