本帖最后由 yaoxinreaps 于 2014-05-08 09:26:21 编辑

解决方案 »

  1.   

    这个location的值从哪里取出来的呢?是不是前台页面传进来的?
      

  2.   

    --写个存储过程
    CREATE PROCEDURE [GetG1ByLRC]
    @L int,
    @R int,
    @C int
    As
    select * from G2 where 名称 in (select 名称 from G1 where Location = ''+cast(@L as varchar(50))+'层'+cast(@R as varchar(50))+'行'+cast(@C as varchar(50))+'列')
      

  3.   

    同意楼上那个的方法 或者你在前台拼好“l层r行c列” 然后后台直接用
      

  4.   

    不好意思还是不懂,我程序是用c#的,该怎么写这个create procedure呢?而且其实后面还有模糊查找,就比如只给一个参数l,其他两个参数不设定,这又该如何?这个弄得我太头大了。
      

  5.   

    看我给楼上朋友的回复,如果拼凑的话是不是没法进行模糊查找了?在C#中该怎么操作啊具体?主要是这个设计到两个表了,一个表的时候我倒找到了方法,就像这样:
    "select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。
      

  6.   

    ...跟几个表有什么关系。
    你的"select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。
    那么"select * from G2 where 名称 in (select 名称 from G1 where Location = '" + l + "层" + r + "行" + c + "列')" 就绝对可以。
    即使出问题,也不是SQL端的事了。另这跟模糊查询有啥关系,哪模糊了? 
      

  7.   

    这个你肯定需要写个存储过程接收程序传过来的参数,然后用动态SQL实现CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
    @floor int,
    @row int,
    @col int
    AS
    BEGIN
    declare @sql varchar(max)
    set @sql = 'select * from G2 where 名称 in (select 名称 from G1 where Location = '+@floor+'层'+@row+'行'+@col+'列)'
    exec(@sql)
    END
    GO
      

  8.   

    用execute('sql语句')或者sp_executesql,动态执行sql语句的方法,可以用变量的形式