# 求一条SQL语句

``````
SELECT * FROM View_RESVT  WHERE ((WO ='1102027') OR (JOBNO ='1102027')) and  1=1 and PRODLOC='X' order by CODE``````

``````
SELECT * FROM View_RESVT  WHERE ((WO in ('1102027','1102024','1102021')) OR (JOBNO in ('1102027','1102024','1102021'))) and  1=1 and PRODLOC='X' order by CODE
``````

``````
SELECT * FROM View_RESVT  WHERE ((WO in ('1102027','','')) OR (JOBNO in ('1102027','',''))) and  1=1 and PRODLOC='X' order by CODE
``````

...全文
71 点赞 收藏 13

13 条回复

liy116 2011-03-21
``SELECT * FROM View_RESVT  WHERE (WO ='1102027' OR JOBNO ='1102027') and  1=1 and PRODLOC='X' ORDER BY CODE,WO``

liy116 2011-03-21

Mr_Nice 2011-03-21
[Quote=引用楼主 liy116 的回复:]

SQL code

SELECT * FROM View_RESVT WHERE ((WO ='1102027') OR (JOBNO ='1102027')) and 1=1 and PRODLOC='X' order by CODE

SQ……
[/Quote]

``````--@i，@j 拼成你想要的条件

@sql  = 'select * from view_resvt where ((wo = @i) or (jobno = @j)) and 1= 1 and prodloc =''X'''
exec (@sql)
``````

[Quote=引用 4 楼 liy116 的回复:]

SQL code
DECLARE @str1 VARCHAR(MAX)
SET @str1 = ',1102027,1102024,1102021,'

SELECT *
FROM View_RESVT
WHERE (CHARINDEX(',' + WO + ',', @str1) > 0 OR CHARINDEX(',' + JOBNO + ……
[/Quote]效率问题，你这样写一点办法都没有，索引都用不到

[Quote=引用 3 楼 liy116 的回复:]
SQL code
SELECT * FROM View_RESVT WHERE CHARINDEX('1102027',(WO,JOBNO))>0

[/Quote]看2楼

liy116 2011-03-21
[Quote=引用 2 楼 wwwwgou 的回复:]
SQL code
DECLARE @str1 VARCHAR(MAX)
SET @str1 = ',1102027,1102024,1102021,'

SELECT *
FROM View_RESVT
WHERE (CHARINDEX(',' + WO + ',', @str1) > 0 OR CHARINDEX(',' + JOBNO + ',', @str1) > 0)
……
[/Quote]

liy116 2011-03-21
``SELECT * FROM View_RESVT WHERE CHARINDEX('1102027',(WO,JOBNO))>0``

Shawn 2011-03-21
``````DECLARE @str1 VARCHAR(MAX)
SET @str1 = ',1102027,1102024,1102021,'

SELECT *
FROM   View_RESVT
WHERE  (CHARINDEX(',' + WO + ',', @str1) > 0 OR CHARINDEX(',' + JOBNO + ',', @str1) > 0)
AND 1 = 1
AND PRODLOC = 'X'
ORDER  BY CODE ``````

sysuleiw 2011-03-21

sysuleiw 2011-03-21

Xiao_Ai_Mei 2011-03-21

2.1w+

MS-SQL Server 疑难问题