I have to select one table out of two to fetch data depending on particular condition i.e. month less than current month will fetch data from table A and month equals or greater than current month will fetch data from table B

<FAKE SIGNATURE>

You should handle that in your application layer, not in SQL. If you do want to handle it in SQL then you should use "sproc delegates" to avoid building dynamic sql.

sproc - Determined which table to call: A or B
sprocA - Call table A
sprocB - Call table B

This lets you maintain having a strongly typed query so your execution plans will be cached and reused.

If I dont have to use stored procedure then is there any other option?

Yes... How do you want to approach it?

Actually i am looking for something like that

select rows from A or B
from switch(condition){case 1: A; case 2: B}


assumption rows in A and B are same

is this possible or correct approach to do this?

Yes but not with a case:

DECLARE @bit bit
SET @BIT = 1
IF @BIT = 0
BEGIN
  Select * From Sensors
END ELSE
BEGIN
  Select * From Servers
END

Hey , means u want to fetch data from table A,B

Select a.column_name  , a.column_name , b.column_name from
a,b where col_name = a.month and col_name > a.month

Nice Meet
Can, we update VIEW Please answer me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.