--写个存储过程 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))+'列')
看我给楼上朋友的回复,如果拼凑的话是不是没法进行模糊查找了?在C#中该怎么操作啊具体?主要是这个设计到两个表了,一个表的时候我倒找到了方法,就像这样: "select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。
...跟几个表有什么关系。 你的"select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。 那么"select * from G2 where 名称 in (select 名称 from G1 where Location = '" + l + "层" + r + "行" + c + "列')" 就绝对可以。 即使出问题,也不是SQL端的事了。另这跟模糊查询有啥关系,哪模糊了?
这个你肯定需要写个存储过程接收程序传过来的参数,然后用动态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
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))+'列')
"select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。
你的"select * from InWasteInfo where Location = '" + l + "层" + r + "行" + c + "列'"可以。
那么"select * from G2 where 名称 in (select 名称 from G1 where Location = '" + l + "层" + r + "行" + c + "列')" 就绝对可以。
即使出问题,也不是SQL端的事了。另这跟模糊查询有啥关系,哪模糊了?
@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