日期:2014-05-16  浏览次数:20866 次

用一条语句删除表里除了满足以下几个条件外的所有记录该怎么办?
表product里typeid字段的值有OT160、OT190、OT260、OT290、OT460、OT490以及其他几种值,现在只需要保留typeid为OT160/OT190/OT260/OT290/OT460/OT490的记录,其他的全部不需要,如何能用一条语句删除那些记录?
有朋友告诉我语句:
delete   from   product   where   typeid   not   in(OT160、OT190、OT260、OT290、OT460、OT490)
表里typeid类型为字符型的,不是数字型。
我是这么写的:
<!--#include   file= "Conn.asp "   -->
<%
        Dim   Sql,Rs
        Set   Rs=Server.CreateObject( "ADODB.RecordSet ")
                        Sql= "delete   from   product   where   TypeId   not   in(OT160、OT190、OT260、OT290、OT460、OT490) "
Connshouhou.ExeCute(Sql)
                Rs.Close:Set   Rs=Nothing
%>
Conn.asp代码如下:
<%
Dim   Shouhou_DbName,Connstrsh,Conn
        Shouhou_DbName= "../DataBase/product.mdb "
        Connstrsh   =   "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   &   Server.MapPath(Shouhou_DbName)
Set   Conn=Server.CreateObject( "ADODB.CONNECTION ")
Conn.Open   Connstrsh
%>
怎么提示
Microsoft   JET   Database   Engine   错误   '80040e10 '  

至少一个参数没有被指定值。  

do.asp,行15   ?
15行就是Connshouhou.ExeCute(Sql),问题会在哪里?

------解决方案--------------------
--不能用顿号,且因为是字符,需要用单引号扩起来

delete *
from product
where typeid not in ( 'OT160 ', 'OT190 ', 'OT260 ', 'OT290 ', 'OT460 ', 'OT490 ')
------解决方案--------------------
delete * from TT
where typeid not in ( 'OT160 ', 'OT190 ', 'OT260 ', 'OT290 ', 'OT460 ', 'OT490 ')