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

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

Trying to compose a Stored Procedure at SQL server with programmer logic but not working(嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲過程但不起作用)
本文介紹了嘗試使用程序員邏輯在 SQL 服務(wù)器上編寫存儲過程但不起作用的處理方法,對大家解決問題具有一定的參考價(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

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

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è)存儲過程工作?我的邏輯很好,但是我找不到將其轉(zhuǎn)換為 SQL 邏輯的方法

在這種情況下轉(zhuǎn)換為 if else 邏輯時(shí),賦值會出錯(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ù)器上編寫存儲過程但不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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(從逗號或管道運(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)
主站蜘蛛池模板: 中文字幕国产视频 | 久久婷婷av| 久久久久久久国产 | 久久久久国色av免费观看性色 | 狠狠操天天操 | 中文字幕一区二区三区四区五区 | 亚洲国产精品成人无久久精品 | 久色网 | 国产精品久久久久久52avav | 人人天天操 | 亚洲国产成人精品久久久国产成人一区 | 四季久久免费一区二区三区四区 | 日韩av.com | 亚洲精品毛片av | 成人二区| 日韩中文字幕网 | 亚洲精品高清视频在线观看 | 日韩欧美中文 | 色婷婷综合网站 | 日本大香伊一区二区三区 | 欧美理伦片在线播放 | 精品一区二区三区在线观看国产 | 婷婷五月色综合 | 国产精品久久久久久久午夜片 | 黄色免费观看网站 | 一区二区蜜桃 | 国产日韩久久 | 亚洲成av人片在线观看无码 | 国产一区免费视频 | 99久久婷婷国产综合精品电影 | 亚洲bt 欧美bt 日本bt | 伊人网综合在线观看 | 国产美女自拍视频 | 免费欧美视频 | 一区二区在线观看免费视频 | 久久久www成人免费精品张筱雨 | 美女视频网站久久 | 久久99精品国产 | 免费av在线网站 | 毛片a级| 国产精品亚洲成在人线 |