473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Condition as part of FROM statement???

I'm trying to have the FROM statement in a SQL query result in a different database depending on the date.

In the middle of each month, our system puts the most recent data in a NEXT database, then at the beginning of the next month NEXT is put into CURRENT and NEXT is emptied.

I want my query to always use the most up-to-date database, or from the first to the 20th use CURRENT, thereafter use NEXT. I've tried to do this with a CASE statement, but I keep getting syntax errors.

Here's a sample of the query that failed:
Expand|Select|Wrap|Line Numbers
  1.     SELECT stuff.id
  2.     FROM    
  3.     case when day(getdate())>19 then CURRENT.dbo.facts 
  4.         else NEXT.dbo.facts
  5.         end
  6.     as stuff
  7.  
Does anyone have an idea of how I can put a condition in my FROM statement?

Thanks,


Dante
Feb 23 '09 #1
4 1454
ck9663
2,878 Expert 2GB
Do you need this to return a single value or a group of recordset?


-- CK
Feb 24 '09 #2
CK:

Thanks for your reply.

I'm working with a view that I'd like to keep up with the latest data. I believe this means that I'm looking for a recordset.

Thanks.

Dante

PS. I'm not trained as a technical person.
Feb 24 '09 #3
ck9663
2,878 Expert 2GB
You have two options:

1. Use a table-function instead of a view.

2. Use UNION (watch out for the difference in table structure), add a new column to identify where the record came from. Use the entire UNION as subquery and use WHERE to grab those records coming from whichever database you want.



-- CK
Feb 24 '09 #4
Thanks,

I love the union query idea, although I may end up using the function instead.


Dante
Feb 24 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: news | last post by:
I'm trying out the Zend Development Environment 4, and for the most part I like it, except for two things. It seems to think certain lines that are perfectly valid are bugs. Like this: while...
2
by: mr_mach7 | last post by:
I have a situation in which I want to dynamically build a SQL statement based upon criteria. The statement would contain different fields depending upon the criteria. I created a Stored Procedure...
6
by: Shill | last post by:
I have several questions. In C, AFAIU, a for loop is just syntactic sugar for a while loop. for (i1; i2; i3) i4; is equivalent to i1 while (i2) {
1
by: Daniel Bass | last post by:
Using VC#.Net, I want to take a statement, that loosely follows the rules of an SQL'a "WHERE" statement, and determine whether that statement is true or false. For example: ( ( Head = 'abc')...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
4
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud...
0
by: Rob R. Ainscough | last post by:
I'm pretty frustrated right now, but I'm unable to get a Launch Condition to work at all in my Condition statement of a Registry entry. (working on a Deployment Project) 1. In Launch...
5
by: jimc52 | last post by:
Hello Everyone: I am hoping one of the gurus here will give me some help. I have designed a form with some check boxes. I put the checkboxes there on the form so later I could use them as flags on...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.