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

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

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