张
张丽敏
Unregistered / Unconfirmed
GUEST, unregistred user!
USE pubs
GO
CREATE PROCEDURE find_books2 @au_lname varchar(20) AS
if @au_lname <> ' '
set @au_lname = @au_lname + '%'
else
set @au_lname = '%' --查找所有记录(不限制au_lame)
SELECT t.title_id, t.title
FROM authors a, titleauthor ta, titles t
WHERE a.au_id = ta.au_id AND ta.title_id = t.title_id
AND a.au_lname LIKE @au_lname + '%'
GO
EXEC find_books2 'ring'
下面是结果集:
title_id title
-------- ---------------------------------------------------------------
MC3021 The Gourmet Microwave
PS2091 Is Anger the Enemy?
PS2091 Is Anger the Enemy?
PS2106 Life Without Fear
(4 row(s) affected)
我要查找 (a.au_lname 符合所有条件的记录, 不限制a.au_lname):
EXEC find_books2 ' '
这样当a.au_lname 等于''或null的记录出不来.
~~~~~~~~~~~~~~~~~~~~
有什么办法达到目的??
谢谢!!
GO
CREATE PROCEDURE find_books2 @au_lname varchar(20) AS
if @au_lname <> ' '
set @au_lname = @au_lname + '%'
else
set @au_lname = '%' --查找所有记录(不限制au_lame)
SELECT t.title_id, t.title
FROM authors a, titleauthor ta, titles t
WHERE a.au_id = ta.au_id AND ta.title_id = t.title_id
AND a.au_lname LIKE @au_lname + '%'
GO
EXEC find_books2 'ring'
下面是结果集:
title_id title
-------- ---------------------------------------------------------------
MC3021 The Gourmet Microwave
PS2091 Is Anger the Enemy?
PS2091 Is Anger the Enemy?
PS2106 Life Without Fear
(4 row(s) affected)
我要查找 (a.au_lname 符合所有条件的记录, 不限制a.au_lname):
EXEC find_books2 ' '
这样当a.au_lname 等于''或null的记录出不来.
~~~~~~~~~~~~~~~~~~~~
有什么办法达到目的??
谢谢!!