mysql = "select * from chanpingzhanshi_table where "
if textbox1.text<>"" then
mysql=mysql & " and title='"+textbox1.text+"'"
end if
if dropdownlist1.selectedindex<>0 then
mysql=mysql & " and xangyedalei='"+dropdownlist1.selecteditem.text+"'"
end if
if dropdownlist2.selectedindex<>0 then
mysql=mysql & " and xangyezilei='"+dropdownlist2.selecteditem.text+"'"
end if
if dropdownlist3.selectedindex<>0 then
mysql=mysql & " and changdi='"+dropdownlist3.selecteditem.text+"'"
end if
mysql = mysql & " order by cpid desc"
mysql = replace(mysql,"where and","where")
mysql = replace(mysql,"where order","order")
Response.Write(mysql)
BEGIN
SET @strChoice = 'NewsState = @ckNewsState '
SET @strNewsTitle = '%'+@NewsTitle+'%'
SET @strNewsKeyWord = '%'+@NewsKeyWord+'%'
SET @strNewsContent = '%'+@NewsContent+'%'
If @NewsTitle <> ''
BEGIN
SET @strChoice = @strChoice + ' AND NewsTitle LIKE @ckNewsTitle'
END
If @NewsKeyWord <> ''
BEGIN
SET @strChoice = @strChoice + ' AND NewsKeyWord LIKE @ckNewsKeyWord'
END
If @NewsContent <> ''
BEGIN
SET @strChoice = @strChoice + ' AND NewsContent LIKE @ckNewsContent'
END
If @NewsTypeId <> 0
BEGIN
SET @strChoice = @strChoice + ' AND NewsTypeId = @ckNewsTypeId'
END
If @NewsProvince <> 0
BEGIN
SET @strChoice = @strChoice + ' AND NewsProvince = @ckNewsProvince'
END
If @NewsProductTypeID <> 0
BEGIN
SET @strChoice = @strChoice + ' AND NewsProductTypeID = @ckNewsProductTypeID'
END
If @NewsProductID <> 0
BEGIN
SET @strChoice = @strChoice + ' AND NewsProductID = @ckNewsProductID'
END
If @MainNews <> 2
BEGIN
SET @strChoice = @strChoice + ' AND MainNews = @ckMainNews'
END
SET @strSQL = 'SELECT NewsId, NewsTitle, NewsFileName, NewsDate '+
'FROM Web_News WHERE '+@strChoice+' ORDER BY NewsDate DESC'
EXECUTE sp_executesql @strSQL,
N'@ckNewsState int, @ckNewsTitle nvarchar(1000), @ckNewsKeyWord nvarchar(100), @ckNewsContent nvarchar(1000),
@ckNewsTypeId int=0, @ckNewsProvince int, @ckNewsProductTypeID int, @ckNewsProductID int, @ckMainNews int',
@ckNewsState=@NewsState, @ckNewsTitle=@strNewsTitle, @ckNewsKeyWord=@strNewsKeyWord, @ckNewsContent=@strNewsContent,
@ckNewsTypeId=@NewsTypeId, @ckNewsProvince=@NewsProvince, @ckNewsProductTypeID=@NewsProductTypeID, @ckNewsProductID=@NewsProductID, @ckMainNews=@MainNews
END
GO