CREATE PROCEDURE GridView_Select
@title nvarchar(50),
@key nvarchar(50)
AS
select au_id,au_lname,au_fname,phone,address,city,state,zip,contract
from authors
where @title like '%@key%'
GO
===========================
@title这里是有问题,@title应该定义为什么类型?字段名可以是用参数的吗?
======================
@title nvarchar(50),
@key nvarchar(50)
AS
select au_id,au_lname,au_fname,phone,address,city,state,zip,contract
from authors
where @title like '%@key%'
GO
===========================
@title这里是有问题,@title应该定义为什么类型?字段名可以是用参数的吗?
======================
CREATE PROCEDURE GridView_Select
@title nvarchar(50),
@key nvarchar(50)
AS
declare @sql nvarchar(4000)
set @sql=' select au_id,au_lname,au_fname,phone,address,city,state,zip,contract from authors where ' + @title + ' like ''%'+ @key +'%'''
exec @sql
GO
@title nvarchar(50),
@key nvarchar(50)
AS
declare @sql nvarchar(4000)
set @sql=N' select au_id,au_lname,au_fname,phone,address,city,state,zip,contract from authors where ' + @title + N' like ''%'+ @key +N'%'''
exec(@sql)GO
CREATE PROCEDURE GridView_Select
@title nvarchar(50),
@key nvarchar(50)
AS
declare @sql nvarchar(4000)
if((@key is null)or (@key=''))
begin
set @sql=N' select au_id,au_lname,au_fname,phone,address,city,state,zip,contract from authors'
end
else
begin
set @sql=N' select au_id,au_lname,au_fname,phone,address,city,state,zip,contract from authors where ' + @title + N' like ''%'+ @key +N'%'''
exec(@sql)
end
GO//
说明@key是直接中textbox控件中获取的.但当textbox中什么都不写的时候不能通过if((@key is null)or (@key=''))