Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm close, now I am just having trouble with this code. It says I need to add exists somewhere? Thanks for the help!

SELECT (SELECT UA#SacmiDataLog_2013.NS_Inlet_T
                  , UA#SacmiDataLog_2013.NSFlowRate
                  , UA#SacmiDataLog_2013.NSHeaterTank
                  , UA#SacmiDataLog_2013.NS_Outlet_T
                  , UA#SacmiDataLog_2013.NSTrPrAvg
                  , UA#SacmiDataLog_2013.NSPump1
                  , UA#SacmiDataLog_2013.NSPump2
                  , UA#SacmiDataLog_2013.NS_Visc
                  , UA#SacmiDataLog_2013.NS_Burner_B
             WHERE
               UA#SacmiDataLog_2013.NSHeatBatch = 'G23169') AS expr1
          , (SELECT UA#SacmiDataLog_2013.OS_Inlet_T
                  , UA#SacmiDataLog_2013.OS_Outlet_T
                  , UA#SacmiDataLog_2013.OS_Burner_B
                  , UA#SacmiDataLog_2013.OSViscosity
                  , UA#SacmiDataLog_2013.OSHeaterTank
                  , UA#SacmiDataLog_2013.OSPump1
                  , UA#SacmiDataLog_2013.OSPump2
                  , UA#SacmiDataLog_2013.OSTrPrAvg
             WHERE
               UA#SacmiDataLog_2013.OSHeatBatch = 'G23169') AS expr2

FROM dbo.UA#SacmiDataLog_2013

share|improve this question
    
So lets say G22166 was made on 1/1/13 on the new side. On the old side G22166 was made again on 4/1/13. Is there a way I pick the date 4/1/13 and have only the Old Side data come up? –  Joe Grozio Jun 13 '13 at 17:55
    
I'm confused because you say that a batch could be produced on both sides, and yet you say you need to only select results from the side where the batch is being produced. It would help to see a better view of the table structure. –  Ducain Jun 13 '13 at 17:56
    
Looking at your most recent comment there, my answer, given the information you've shared, is sure: only select from the OSHeatBatch column. Your WHERE clause is looking at the NS and OS columns. But again, I'm betting I don't have enough info to correctly answer this. EDIT: Or are you saying you only want to see the most recently entered batch? –  Ducain Jun 13 '13 at 17:58
    
It wont let me add an image so let me try and edit it to make it easier to understand –  Joe Grozio Jun 13 '13 at 18:18
    
You certainly can add images here, but tell you what, it would really help if you added your query as it is now, as well as the results you're receiving. You can just add this as text (there is a button for formatting as code in the editor). Then you could more easily explain what results you would like to see. –  Ducain Jun 13 '13 at 18:26

2 Answers 2

up vote 0 down vote accepted

Then, Do Like this, I hope this would helps :

SELECT  * FROM( 
    SELECT NSField1 as DataColumnNameSame1,NSField2 as DataColumnNameSame2 FROM SAMETABLE AS NS WHERE NS.BATCH='111111' AND RUNDATE BETWEEN '1/14/13' AND '1/16/13' 

UNION ALL

    SELECT OSField1 as DataColumnNameSame1,OSField2 as DataColumnNameSame2 FROM SAMETABLE AS NS WHERE OS.BATCH='111111' AND RUNDATE BETWEEN '1/14/13' AND '1/16/13' 

) AS DATA 
    --WHERE CRITERIA IF NECESSARY IN THIS LEVEL TOO, ONCE AGAIN YOU CAN FILTER FROM HERE ALSO IF NEEDED. HOPE THIS HELPS.
share|improve this answer
    
nevermind, it does work lol. thanks so much! –  Joe Grozio Jun 14 '13 at 18:21
    
Ya, You welcome... And, glad it worked. –  N.p Subedi Jun 15 '13 at 5:52

Did you tried this way :

where (NSHeatBatch= 'G22166' or OSHeatBatch= 'G22166') 
and RunDate between '1/14/13' and '1/16/13'

Many times your Braces are so much important things to define query. Lets try that way...!

share|improve this answer
    
This helps but it also allows all values in that row to appear. Lets say a user doesn't know if the batch is on the New side or Old, they just know that it was made between two dates. How would they be able to make a graph if both NS and OS values appear? –  Joe Grozio Jun 14 '13 at 12:33
    
Then, You have to put an OR operator between that two conditions. So, whether the Batch Matched or in between dates,both will appear. Otherwise, Im feeling now that you to have split your table into 2 for NEW SIDE and OLD Side. Then you can query from the Both tables using and retrieve the data with UNION with the Conditions on both tables. –  N.p Subedi Jun 14 '13 at 12:36
    
I don't have permission to make a new table. Would an if else or case statement work? –  Joe Grozio Jun 14 '13 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.