在存储过程中声明的变量@booktypeid,@booktypeid_f起不了作用
程序源代码如下:
ALTER PROCEDURE [dbo].[BOOK_frm_InsertBook]
(
@type char(100)=null,
@bookname char(18)=null,
@booknum char(20)=null,
@bookISBN char(18)=null,
@booktypename char(50)=null,
@bookauthor char(30)=null,
@bookpress char(50)=null,
@bookpressdate datetime=null,
@bookprice money =null,
@bookplace char(50)=null,
@bookintrodution text=null,
@booktext text=null,
@bookborrowflag char(15)=null
)
AS
BEGIN
IF( @type = 'btn_SaveAndNext_Click')
BEGIN
declare @booktypeid int;
declare @booktypeid_f int;
if( @booktypename != null)
BEGIN
SELECT @booktypeid=BOOK_TYPE_ID, @booktypeid_f=BOOK_TYPE_ID_F
FROM BOOK_TYPE
WHERE @booktypename=BOOK_TYPE_NAME
END
INSERT INTO BOOK_Rec
( BOOK_NAME, BOOK_NUM, BOOK_ISBN, BOOK_AUTHOR, BOOK_PRESS, BOOK_PRESS_DATE,
BOOK_PRICE, BOOK_PLACE, BOOK_FLAG_BORROW, BOOK_INTRODUTION, BOOK_TEXT,
BOOK_TYPE_ID, BOOK_TYPE_ID_F
)
VALUES ( @bookname, @booknum, @bookISBN, @bookauthor, @bookpress, @bookpressdate,
@bookprice, @bookplace, @bookborrowflag, @bookintrodution, @booktext,
@booktypeid, @booktypeid_f
)
END
END
执行时,没有错误但@booktypeid和@booktypeid_f的值却为NULL。
请问,为什么会这样呀。
说明:
表BOOK_TYPE(书的类型)是表BOOK_Rec(书的详细信息)的类型索引表,根据BOOK_TYPE_ID或者BOOK_TYPE_ID_F在表BOOK_TYPE中都可以查到具体的类型名字。
------解决方案--------------------SQL code
if( @booktypename != null)
改为
if @booktypename is not null
------解决方案--------------------
SQL code
ALTER PROCEDURE [dbo].[BOOK_frm_InsertBook]
(
@type char(100)=null,
@bookname char(18)=null,
@booknum char(20)=null,
@bookISBN char(18)=null,
@booktypename char(50)=null,
@bookauthor char(30)=null,
@bookpress char(50)=null,
@bookpressdate datetime=null,
@bookprice money =null,
@bookplace char(50)=null,
@bookintrodution text=null,
@booktext text=null,
@bookborrowflag char(15)=null
)
AS
BEGIN
IF( @type = 'btn_SaveAndNext_Click')
BEGIN
declare @booktypeid int;
declare @booktypeid_f int;
if( @booktypename is not null)
BEGIN
SELECT @booktypeid=BOOK_TYPE_ID, @booktypeid_f=BOOK_TYPE_ID_F
FROM BOOK_TYPE
WHERE @booktypename=BOOK_TYPE_NAME
END
INSERT INTO BOOK_Rec
( BOOK_NAME, BOOK_NUM, BOOK_ISBN, BOOK_AUTHOR, BOOK_PRESS, BOOK_PRESS_DATE,
BOOK_PRICE, BOOK_PLACE, BOOK_FLAG_BORROW, BOOK_INTRODUTION, BOOK_TEXT,
BOOK_TYPE_ID, BOOK_TYPE_ID_F
)
VALUES ( @bookname, @booknum, @bookISBN, @bookauthor, @bookpress, @bookpressdate,
@bookprice, @bookplace, @bookborrowflag, @bookintrodution, @booktext,
@booktypeid, @booktypeid_f
)
END
END
------解决方案--------------------