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?什么時候不能投射為日期?)
主站蜘蛛池模板: 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 北京公寓出租网-北京酒店式公寓出租平台 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 培训中心-翰香原香酥板栗饼加盟店总部-正宗板栗酥饼技术 | 隧道窑炉,隧道窑炉厂家-山东艾瑶国际贸易 | 大数据营销公司_舆情监测软件_上海SEO公司-文军营销官网 | 北京开源多邦科技发展有限公司官网 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 杭州货架订做_组合货架公司_货位式货架_贯通式_重型仓储_工厂货架_货架销售厂家_杭州永诚货架有限公司 | 学习虾-免费的学习资料下载平台| 贴板式电磁阀-不锈钢-气动上展式放料阀-上海弗雷西阀门有限公司 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 | TPM咨询,精益生产管理,5S,6S现场管理培训_华谋咨询公司 | 江苏南京多语种翻译-专业翻译公司报价-正规商务翻译机构-南京华彦翻译服务有限公司 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 六自由度平台_六自由度运动平台_三自由度摇摆台—南京全控科技 | 找培训机构_找学习课程_励普教育 | YT保温材料_YT无机保温砂浆_外墙保温材料_南阳银通节能建材高新技术开发有限公司 | 电渗析,废酸回收,双极膜-山东天维膜技术有限公司 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 | 广州昊至泉水上乐园设备有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | 山东商品混凝土搅拌楼-环保型搅拌站-拌合站-分体仓-搅拌机厂家-天宇 | 锂电池生产厂家-电动自行车航模无人机锂电池定制-世豹新能源 | 滤芯,过滤器,滤油机,贺德克滤芯,精密滤芯_新乡市宇清流体净化技术有限公司 | 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 液氮罐_液氮容器_自增压液氮罐-北京君方科仪科技发展有限公司 | 微型气象仪_气象传感器_防爆气象传感器-天合传感器大全 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器 | 潍坊青州古城旅游景点攻略_青州酒店美食推荐-青州旅游网 | 线材成型机,线材折弯机,线材成型机厂家,贝朗自动化设备有限公司1 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 科昊仪器超纯水机系统-可成气相液氮罐-美菱超低温冰箱-西安昊兴生物科技有限公司 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 生鲜配送系统-蔬菜食材配送管理系统-连锁餐饮订货配送软件-挪挪生鲜供应链管理软件 |