久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲(chǔ)過程

Trying to compose a Stored Procedure at SQL server with programmer logic but not working(嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲(chǔ)過程但不起作用)
本文介紹了嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲(chǔ)過程但不起作用的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

好的,我的表 - SQL Server 2014

Ok here my table - SQL server 2014

假設(shè)我有以下變量

Computer Hardware > Video Cards

所以計(jì)算機(jī)硬件是父節(jié)點(diǎn),顯卡是子節(jié)點(diǎn)

So Computer Hardware is being parent node and Video Cards is being children

這里是我的存儲(chǔ)過程,它是由程序員邏輯編寫但不起作用

Here my stored procedure which is written by programmer logic but not working

Create Procedure insert_Product_Category_With_Parent_Node_Key_pair
(
@cl_CategoryName nvarchar(200),
@cl_ParentCategoryName nvarchar(200),
@cl_InsertedId int Output
)
As
Begin

declare @cl_ParentCategoryId int

declare @cl_Parent_Node_Exists_CategoryId int

set @cl_ParentCategoryId = ISNULL((select cl_CategoryId 
from tblProductCategories 
where cl_CategoryName=@cl_ParentCategoryName),0)

set @cl_Parent_Node_Exists_CategoryId = ISNULL((select cl_CategoryId 
from tblProductCategories 
where cl_CategoryName=@cl_CategoryName 
and 
cl_ParentCategoryId=@cl_ParentCategoryId),0)


CASE

when @cl_Parent_Node_Exists_CategoryId = 0 

then

insert into tblProductCategories (cl_CategoryName,cl_ParentCategoryId)
@cl_InsertedId = INSERTED.cl_CategoryId
values (@cl_CategoryName,@cl_ParentCategoryId)

else

@cl_InsertedId = @cl_Parent_Node_Exists_CategoryId

end

end

SQL 服務(wù)器給出的錯(cuò)誤

The error SQL server giving

    Msg 156, Level 15, State 1, Procedure insert_Product_Category_With_Parent_Node_Key_pair, Line 17
Incorrect syntax near the keyword 'CASE'.
Msg 102, Level 15, State 1, Procedure insert_Product_Category_With_Parent_Node_Key_pair, Line 22
Incorrect syntax near '@cl_InsertedId'.

好的,我希望它如何工作

Ok here how i want it work

declare @returned_product_categoryId int
exec insert_Product_Category_With_Parent_Node_Key_pair
    @cl_CategoryName = 'Video Cards',
    @cl_ParentCategoryName = 'Computer Hardware'
    @returned_product_categoryId = @cl_InsertedId output
select @returned_product_categoryId

最后我的問題是如何使這個(gè)存儲(chǔ)過程工作?我的邏輯很好,但是我找不到將其轉(zhuǎn)換為 SQL 邏輯的方法

在這種情況下轉(zhuǎn)換為 if else 邏輯時(shí),賦值會(huì)出錯(cuò)

推薦答案

Create Procedure insert_Product_Category_With_Parent_Node_Key_pair
(
    @cl_CategoryName nvarchar(200),
    @cl_ParentCategoryName nvarchar(200),
    @cl_InsertedId int Output
)
AS
BEGIN
   SET NOCOUNT ON;

declare @cl_ParentCategoryId int;
declare @cl_Parent_Node_Exists_CategoryId int;

set @cl_ParentCategoryId = ISNULL((select cl_CategoryId 
                                    from tblProductCategories 
                                    where cl_CategoryName = @cl_ParentCategoryName),0)

set @cl_Parent_Node_Exists_CategoryId = ISNULL((select cl_CategoryId 
                                                from tblProductCategories 
                                                where cl_CategoryName = @cl_CategoryName 
                                                and 
                                                cl_ParentCategoryId = @cl_ParentCategoryId),0)



     IF (@cl_Parent_Node_Exists_CategoryId = 0)
      BEGIN
            insert into tblProductCategories (cl_CategoryName,cl_ParentCategoryId)
            values (@cl_CategoryName,@cl_ParentCategoryId)

            SET @cl_InsertedId = SCOPE_IDENTITY();
       END
     ELSE
      BEGIN
        SET @cl_InsertedId = @cl_Parent_Node_Exists_CategoryId;
      END
END

這篇關(guān)于嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲(chǔ)過程但不起作用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 亚洲一区二区 | 欧美激情视频一区二区三区在线播放 | 欧美性网| 91在线综合| 免费黄色片视频 | 欧美性video 精品亚洲一区二区 | 毛片一区二区三区 | 国产一级免费视频 | 色婷婷综合在线观看 | 国产精品1区2区 | 粉嫩av久久一区二区三区 | 欧美日韩综合一区 | 超碰在线人人干 | 性高湖久久久久久久久aaaaa | 国产成人精品一区二区三区网站观看 | 欧美二三区 | 久久久精品一区 | 欧美久久一区二区三区 | 亚洲一区二区久久久 | 色精品| 91精品一区二区三区久久久久久 | 天天天天操 | 国产一区二区在线观看视频 | 中文字幕一区二区三区四区 | 成人h动漫精品一区二区器材 | 91久久综合亚洲鲁鲁五月天 | 国产成人精品一区二 | 日韩欧美大片在线观看 | 成人免费在线观看视频 | 青青久久久 | 国产一区2区 | 亚洲综合色自拍一区 | 日韩成人免费视频 | 日本精品在线一区 | 亚洲视频精品 | 中文字幕综合 | 日韩视频二区 | 亚洲国产精品一区二区久久 | 国产资源一区二区三区 | 国产精品99久久久久久人 | 9色网站 |