0

Hi all,

I'm new to this forum. I'm learning C and embedded SQL. I have a question.

In one of the project am doing, i want to check whether any records with a particular local_id and global_id is there in the database with in the last 90 days. If it is present, then it should fetch various details of those records.

I can implement this in two phases. one query for checking if it is present in the last 90 days. Second one for fetching records based on the output of 1st phase.

But, i believe this could be done in a single SQL Query. I'm not that advanced especially when it comes to embedded SQL. Any help would be highly appreciated. Thanks

3
Contributors
2
Replies
20
Views
2 Years
Discussion Span
Last Post by Frederick2
0

The query itself will determine if you have data.

"select * from table where id = 1 and date > dateadd(d, -90, NOW())"

(of course that's psudo-code so YMMV)

If it returns no results it basically means you have no data.

Basically, your "if exists" check can be summed up by looking at your data and seeing if it exists :-P

0

I suspect you might be right that it can be done in a single statement, but for myself, I seldom get too fancy if there is a conceptually simpler 'brute force' way to do it, so I always first do a SELECT count(*) type statement to see if the return is zero or non-zero, then follow that with an if depending on the prior outcome.

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.