日期:2014-05-18 浏览次数:20571 次
if object_id('SBLX ') is not null
    drop table SBLX 
go
if object_id('selectByMCOrSCCJ') is not null
    drop proc selectByMCOrSCCJ
go
create table SBLX(
MC varchar(30),
SCCJ varchar(30)
)
insert SBLX select 'china','guangdong'
union all select 'china','beijing'
union all select 'usa','newyork'
union all select 'france','paris'
go
create proc selectByMCOrSCCJ
     @MC varchar(30)='',
     @SCCJ varchar(30)=''
AS
declare @sql nvarchar(1000)
if @MC<>'' and @SCCJ<>''
     set @sql=N'select MC,SCCJ from SBLX where MC='''+@MC+N''' and SCCJ='''+@SCCJ+N''''
else if @MC<>'' and @SCCJ=''
     set @sql=N'select MC,SCCJ from SBLX where MC='''+@MC+N''''
else
     set @sql=N'select MC,SCCJ from SBLX where SCCJ='''+@SCCJ+N''''
--print @sql
exec sp_executesql @sql
go
exec selectByMCOrSCCJ 'china',''
drop proc selectByMCOrSCCJ
drop table SBLX