SQL2000 + ASP.NET2.0 + C#
ttape表字段有:
id
tapecode  (磁带编号)
instack   (是否在库,1为在库)ttapeborrow表有:
id
tapecode  (磁带编号)
borrowdate (借出日期)
borrowman  (借人)
returndate (归还日期)现在页面上有一个textbox控件,允许用户输入磁带编号的一部分进行模糊查询找出已经借出的带子。我想应该有两种方法,
一种是结合两个表,找出符合用户输入字符的在表ttapeborrow中存在记录且ttape表instack字段为0,
一种是只查表ttapeborrow,找出符合用户输入字符在表ttapeborrow中存在记录且returndate字段为空这两种方法哪一种比较好呢?SQL语句分别怎么写好呢?

解决方案 »

  1.   


    --方法一
    select tapecode from ttape where instack<>1
    --方法二
    select tapecode from ttapeborrow where returndate is null--个人感觉第一种方法的速度会快一些,但是对于数据量不是很大情况,应该没什么区别
      

  2.   

    一种是结合两个表,找出符合用户输入字符的在表ttapeborrow中存在记录且ttape表instack字段为0
    select id,tapecode,borrowdate,borrowman,returndate from ttapeborrow 
    inner join ttape 
    on ttapeborrow.tapecode= ttape.tapecode and ttape.instack=0
    where ttapeborrow.tapecode like '%你输入的字符串%'一种是只查表ttapeborrow,找出符合用户输入字符在表ttapeborrow中存在记录且returndate字段为空 select id,tapecode,borrowdate,borrowman,returndate from ttapeborrow 
    where ttapeborrow.tapecode like '%你输入的字符串%' and cast(returndate as varchar(50))=''用第二种就OK了,第一种没什么意思,你要的就是借出未还的,那还扯那多干啥啊