views:

29

answers:

1

How to use if and onlf if in a select statement in sql server 2005?

Here is my select statement select Mat_Id,MeasurementId from InTime...

Now i want to show measurementName which is Measurment Table based on MeasurementId..

Mind you MeasurementId is not a foriegn key...

How to make join with Measurement table if there is value in MeasurementId field of InTime Table

alt text

+1  A: 

Use a left join:

SELECT InTime.Mat_Id, InTime.MeasurementId, Measurment.measurementName
FROM InTime
LEFT JOIN Measurment
ON InTime.MeasurementId = Measurment.MeasurementId

If you only want the rows that have measurement names, use an INNER JOIN instead of a LEFT JOIN.

Also, you have a typo: Measurment should be Measurement. I'm not sure if that's a problem with your database or your question.

Mark Byers
@Mark that did the trick...
Pandiya Chendur