0

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>

Edited by peter_budo: Keep It On The Site - Do not manually post &quot;fake&quot; signatures in your posts. Instead, you may create a sitewide signature within the user control panel.

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by waqas royal
0

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.

0

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

0

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?

0

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

Edited by sknake: n/a

0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.