Select Data using date between operator and two unconnected tables - date

I am tryin to resolve this situation. The following piece of code works ok .
SELECT FISCAL_START, DESCRIPTION,
CASE WHEN FISCAL_START BETWEEN DATE'2014-03-31' AND DATE'2014-09-29' THEN DESCRIPTION
ELSE 'Test Failed'
END
FROM GL_PERIOD
what I am trying to achieve is as follows instead of the hard coded dates of 2014-03-31 and 2014-09-29..need to replace those with column names FISCAL_START and FISCAL_END dates from an unconnected view call WORK.
Psuedo code is as follow s...
Show Description from GL_PERIOD where ENTER_DATE (which is in WORK view) is between FISCAL_START and FISCAL_END. Any help will be greatly appreciated.

I think you need this, I just continue your query to add the missing piece:
Here is sqlfiddle that will show you live example: fiddle example
SELECT "FisStart", "Descripton",
CASE WHEN "Entry_Date"
BETWEEN "FisStart"
AND "FisEnd"
THEN "Descripton"
ELSE 'Test Failed'
END
FROM GL_PERIOD
INNER JOIN WORK USING USING ("SrNo")

Related

How to stop upper() from being pulled through as part of Google Sheets QUERY?

I'm unable to find a way of making sure that upper() is not pulled through when using the QUERY function on Google, specifically with SELECT.
I have an example below:
=QUERY(countries, "SELECT UPPER(C)", 1)
But this outputs upper() as one of the cells. In this case the first item of the column is Continent so this pulls through as "upper(Continent)
Example Spreadsheet here
Does anyone know how to fix this so that upper() doesn't appear at all?
try:
=QUERY(QUERY(countries, "select upper(C)"), "offset 1", 0)
=QUERY(QUERY(countries, "select upper(C),upper(B)"), "offset 1", 0)
tho all you need is:
=ARRAYFORMULA(UPPER({C2:C, B2:B}))
or shorter:
=INDEX(UPPER({C2:C, B2:B}))
Found the answer here!
Basically you need to label the column as nothing like so:
=QUERY(countries, "SELECT UPPER(C) label UPPER(C) ''", 1)
Hope this helps someone at some point as it took me a while to find!

Not able to pass complete datetime(Y-m-d H:i:s) in DB::raw in eloquent

$shop=DB::table('shops')
->leftJoin('orderbookings',function($join)
{
$join->on('shops.id','=','orderbookings.shop_id');
$join->on('orderbookings.created_at','>=',DB::raw(date("Y-m-d",strtotime("now"))));
})
->select('shops.*')
->selectRaw('COUNT(orderbookings.id) as totalorder, SUM(orderbookings.grand_total) as gtotal')
->orderBy('shops.shop_name', 'asc')
->groupby('shops.id')
->paginate(10);
Above code working fine(But not giving total order and amount correct) and also gives result almost close to what I want,
But I am not able to give date format (Y-m-d H:i:s), it shows syntax error. I am using Laravel 5.2 version
Note: I want to give time as well with date to rectify result,
On giving [example: 2017-03-08 11:15:00] shows syntax error
working query in mysql
SELECT COUNT(orderbookings.id), SUM(orderbookings.grand_total), shops.shop_name FROMshopsLEFT JOIN orderbookings on orderbookings.shop_id = shops.id and orderbookings.created_at BETWEEN "2015-10-22 17:02:02" AND "2017-03-07 17:02:02" GROUP BY shops.id
But not able to to convert in eloquent
You should be able to do the following:
$join->on('orderbookings.created_at', '>=', date("Y-m-d"));
You don't need to use DB::raw, and leaving the second parameter null for date, assumes "now".
If this doesn't solve your issue, please post the exact error you're seeing.

how to use for each loop in Progress?

Basically i'm trying to do a simple join. I'm a beginner in progress and even if i'm reading always the same things... my problem still unresolved ! :'(
I'm using unixodbc to communicate with my base and this is working like a charm when i'm using simple command like : SELECT * from PUB."Art"
I understood I have to do something who looks like that to join 2 tables :
FOR EACH PUB."Art" WHERE (PUB."Art".IdArt = 16969) ,
EACH PUB."ArtDet" WHERE (PUB."ArtDet".IdArt = PUB."Art".IdArt)
END
But this only return me [ISQL]ERROR: Could not SQLPrepare
I then try to simplify the thing with :
for each PUB."Art": display PUB."Art".IdArt end.
I try to put colon (or not) after the for each loop, using point / comma etc... but I never use the right syntax apparently... or I'm missing a thing to execute this command !
Is anyone can advice me ?
Thx a lot !
You appear to mixing SQL and 4GL syntax.
"FOR EACH" is 4GL. The SQL equivalent is "SELECT".
(If you are using 4GL you do not need then "PUB" prefix and quoting table and field names will not work.)
To do a join with SQL (or the 4GL) use a "," between the table names. For SQL your syntax would look something like:
SELECT * from PUB."Art", PUB."ArtDet"
Gory details regarding WHERE clauses, SQL INNER & OUTER joins etc. can be found in the online documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview
You will want to navigate to your specific release and then find the "SQL" guide.

T-SQL SELECT Statment to Exclude Text Between ( And ) Without Update or Variables

I'm wondering if this is possible, I have a messy set of first name data to work with, and it's shared by other applications so I don't want to run any update statements. But the data will sometime include an AKA such as:
Robert (AKA Bob)
And I am trying to get a clean data where it just says "Robert".
One way I thought of is to use a temp table then CHARINDEX for ( and ) then REPLACE what's between ( and ). This seems like a long winded way to do this.
Is there a smarter way?
EDIT: More examples of the data hell. Sometimes the parenthesis comes in the front or mixed up such as:
(Bill) William
Richard (Dick) Jr.
Untested:
FirstName = case when charindex('(AKA', FirstName) = 0
then FirstName
else substring(FirstName, 1, charindex('(AKA', FirstName)) end
If the noisy string pattern is unpredictable, better to use SQL CLR TVF(table value function), utilize C# code regex. Taking an xml as input parameter, which includes data you need to process, return a table with data processed.
Pieter got the ball rolling for me! Thank you for getting me started on the right track!
SELECT
CASE WHEN FirstName like '%)%'
THEN REPLACE(FirstName,
SUBSTRING(FirstName,CHARINDEX('(',FirstName),CHARINDEX(')',FirstName)-CHARINDEX('(',FirstName)+1),'')
ELSE FirstName END

How can I display count of imagefield images in views?

I want to display the number of images uploaded to an imagefield, in a views field or views tpl.php. How can I do this? My imagefield is called boatimages. I tried this but it comes out as 0, not the correct number: < ? php print count($fields->field_boatimages) ?>
Ack. I do not think count() works like that.
Why not just do this using Views? Take a look at Arguments > Settings and you'll see 'display record count' which seems like all you would need for this.
My suggestion is install the devel module and use the function dpm to print the variable if you wanna know the structure (print_r() may work too). If count isn't working it's because, you are probably using it with the wrong data.
OR, you could just query the database for the field. I'm gonna provide you instructions for drupal 7 but drupal 6 should be similar.
Check the table field_data_field_boatimages. See how there's a list of your images related with a single entity_id
Then execute this query
SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = ###
Where ### is the entity_id you want to know. You can get it by looking for arg(1) if arg(0) == node in your page.
Now you just have to use php power to print thar result
$query = SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = :eid
$result = db_query($query, array(':eid', $nid))->fetchField();
echo $result;
Drupal 6 would be very similar. Just a little difference in the table names and the query syntax. For example using db_result instead of fetchField()
Anyway good luck!