日期:2014-05-18  浏览次数:20422 次

在存储过程中声明的变量@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

------解决方案--------------------
探讨
我执行存储过程如下:
[BOOK_frm_InsertBook] 'btn_SaveAndNext_Click','呼啸山庄','9787506812047','ISBN 7-5068-1204-5','I.3美洲文学','张天华 编译','中国书籍出版社','2005/04','19','三层五区','','','可供借阅'
但总是出错:
无法将vachar类型转换为datetime类型。……