Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to add an OR I think SQL 2010 2

Status
Not open for further replies.

cjbrown815

IS-IT--Management
Mar 2, 2006
525
US
Hello, I have this statement that is working great. But, the parameter for pH does not have a Print Flag=1 (SAMPLEPARAM.PRINT_FLAG=1))
, so I have to add it in somehow. Like SAMPLEPARAM.PA_NAME like %pH%

When I do an OR at the end of this it blows away most of the other criteria. I need exactly what this statement is pulling, but I need pH brought in as well. Thanks

STATEMENT

SELECT SAMPLE.SAMPLE_ID, SAMPLE.SAMPLE_STATUS, SAMPLE.SUBMITTER, SAMPLE.SAMPLE_TYPE, SAMPLE.TEXT3, SAMPLE.TEXT5,
SAMPLE.DATE3, SAMPLE.REMARKS, SAMPLE.LOT, SAMPLE.PRODUCT_LOT, SAMPLETYPE.ST_TYP, SAMPLETYPE.ST_ID, SAMPLETYPE.ST_NAME,
SAMPLETYPE.ST_DESC, SAMPLEPARAM.PA_NAME, SAMPLEPARAM.TRESULT, SAMPLEPARAM.NRESULT, SAMPLEPARAM.SRESULT, SAMPLEPARAM.ORESULT,
SAMPLEPARAM.SAMPLEPARAM_ID

FROM LIMSProd.dbo.SAMPLE SAMPLE, LIMSProd.dbo.SAMPLEPARAM SAMPLEPARAM, LIMSProd.dbo.SAMPLETYPE SAMPLETYPE

WHERE SAMPLE.SAMPLE_ID = SAMPLEPARAM.SAMPLE_ID AND SAMPLEPARAM.ST_N = SAMPLETYPE.ST_N AND
SAMPLEPARAM.ST_VERS = SAMPLETYPE.ST_VERS AND
((SAMPLE.SAMPLE_TYPE Like 'WKLY_%') AND (SAMPLE.DATE3>=DateAdd(yy,-3,GetDate())) AND (SAMPLEPARAM.PRINT_FLAG=1))
ORDER BY SAMPLE.DATE3, SAMPLE.SAMPLE_TYPE

-CJ

SQL2005// CRXIr2// XP Pro

"Progress lies not in enhancing what is, but in advancing toward what will be"
-KHALIL GIBRAN 1883-1931
 
This line:
Code:
((SAMPLE.SAMPLE_TYPE Like 'WKLY_%') AND (SAMPLE.DATE3>=DateAdd(yy,-3,GetDate())) AND (SAMPLEPARAM.PRINT_FLAG=1))

becomes:
Code:
((SAMPLE.SAMPLE_TYPE Like 'WKLY_%') AND (SAMPLE.DATE3>=DateAdd(yy,-3,GetDate())) AND (SAMPLEPARAM.PRINT_FLAG=1 [COLOR=red]OR  SAMPLEPARAM.PA_NAME like %pH%[/color]))

Lodlaiden

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
try this:

Code:
WHERE SAMPLE.SAMPLE_ID = SAMPLEPARAM.SAMPLE_ID 
      AND SAMPLEPARAM.ST_N = SAMPLETYPE.ST_N 
      AND SAMPLEPARAM.ST_VERS = SAMPLETYPE.ST_VERS 
      AND SAMPLE.SAMPLE_TYPE Like 'WKLY_%'
      AND SAMPLE.DATE3>=DateAdd(yy,-3,GetDate())
      AND (
        SAMPLEPARAM.PRINT_FLAG=1
        Or 
        SAMPLEPARAM.PA_NAME like %pH%
	)

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you

-CJ

SQL2005// CRXIr2// XP Pro

"Progress lies not in enhancing what is, but in advancing toward what will be"
-KHALIL GIBRAN 1883-1931
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top