再帮我转一存储过程,有点复杂
sql="SELECT TOP 4 classId,style_no,id,smallimg,isnew,newtime,Img_Name FROM products where seelevel='c' "
if Request.cookies("cookies_member")=true then
sql=sql&" or seelevel='b' "
if Request.cookies("cookies_allow")=1 then
sql=sql&" or seelevel='a' "
end if
end if
select case products_type
case "Random"
if showedid<>"" then
sql=sql&" and id not in "& showedid &" ORDER BY NEWID()"
else
sql=sql&" ORDER BY NEWID()"
end if
case "recommend"
if showedid<>"" then
sql=sql&" and tj='yes' and id not in "& showedid &" ORDER BY NEWID()"
else
sql=sql&" and tj='yes' ORDER BY NEWID()"
end if
case "new"
if showedid<>"" then
sql=sql&" and DateDiff(d, isnew, getdate())<newtime and id not in "& showedid &" ORDER BY NEWID()"
else
sql=sql&" and DateDiff(d, isnew, getdate())<newtime ORDER BY NEWID()"
end if
end select
问题点数:20、回复次数:1Top
1 楼pengdali()回复于 2002-12-14 18:18:20 得分 20
create procedure aa
@cookies_member bit,
@cookies_allow smallint,
@products_type varchar(100),
@showedid varchar(100)
as
declare @sql varchar(3000)
set @sql='SELECT TOP 4 assId,style_no,id,smallimg,isnew,newtime,Img_Name FROM products where seelevel=''c'' '
if @cookies_member=1
begin
set @sql=@sql+' or seelevel=''b'''
if @cookies_allow=1 then
set @sql=@sql+' or seelevel=''a'''
end
if @products_type='Random'
begin
if @showedid<>''
set @sql=@sql+' and id <>'''+@showedid+''' order by newid()'
else
set @sql=@sql+'ORDER BY NEWID()'
end
else if @products_type='recommend'
begin
if @showedid<>''
set @sql=@sql+' and tj=''yes'' and id <> '''+@showedid+''' ORDER BY NEWID()'
else
....................................你自己改吧!
end
Top




