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

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

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

問題描述

好的,我的表 - SQL Server 2014

Ok here my table - SQL server 2014

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

Computer Hardware > Video Cards

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

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

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

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ù)器給出的錯誤

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

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

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

推薦答案

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ù)器上編寫存儲過程但不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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(從逗號或管道運算符字符串中刪除重復(fù)項)
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久久精品一区二区二区 | 美女福利视频一区 | 自拍偷拍中文字幕 | 亚洲性人人天天夜夜摸 | 亚洲人在线 | 一区二区三区精品视频 | 成人黄色在线视频 | 国产一区 | 在线播放中文字幕 | 久久久久久99 | 欧美日韩在线一区二区三区 | 日韩一级电影免费观看 | 免费在线观看黄网站 | 亚洲品质自拍视频网站 | 国产精品不卡一区 | 久久精品日产第一区二区三区 | 久久久久国产精品一区二区 | 99久久99久久精品国产片果冰 | av中文字幕在线 | 亚洲精品视频一区二区三区 | 欧美爱爱视频 | 日韩中文字幕在线观看 | 啪啪免费| 精品视频在线一区 | 亚洲日韩中文字幕一区 | 国产精品高潮呻吟久久 | 欧美一区2区三区4区公司二百 | 国产精品a久久久久 | 一区二区三区在线播放视频 | 久久精品国产亚洲一区二区三区 | 免费黄色av网站 | 国产福利在线小视频 | 午夜免费电影 | 欧美一区二区视频 | 99亚洲精品 | 国产精品乱码一二三区的特点 | 亚洲视频欧美视频 | 久久国产精品久久久久久久久久 | 鸳鸯谱在线观看高清 | 成人在线国产 |