How to hide alias column in SQL Output? - ms-access-2007

as example, I've the following SQL query ( using Access 2007 )
SELECT ID, FirstMaturityDate, PayMentDate,
iif(PayMentDate>FirstMaturityDate, PayMentDate, FirstMaturityDate)
as Maxdate
from Table 1
Actually, I need the alias Maxdate for further processing, but I
don't want to to see Maxdate as column in output. Is this somehow
possible ?

You didn't specify how you output the data - if you show it in a form or listbox (for example), just don't display the Maxdate column.
(for example, by just not putting a textbox for it on the form)

Create a view that includes all the columns except the column you want to hide.

Related

SQL Server query to get a pre-position No

I am trying to write SQL query, that will display in a new column a 'pre-position number' with values displayed based on the value on the previous position number column row.
I would appreciate any assistance.
Thank you.
You seem to be looking for LAG(). For this to work, you need a column that can be used to order the data, so your RDBMS can assess which record is the previous record to the current one. Assuming that this column is called id, then:
SELECT
id,
position_nr,
LAG(position_nr) OVER(ORDER BY id) pre_position_nr
FROM mytable
You want to use LAG(). To get the 0, use the three argument form:
SELECT position_no,
LAG(position_no, 1, 0) OVER (ORDER BY position_no) as pre_position_no
FROM mytable;
This assumes that you are ordering by position_no, as suggested by your sample code.

Can I use SQL to edit a piece of a record in a group of rows?

The records of one column in my table have a letter/dash prefix (B-290151626). I need to remove the letter/dash without changing the rest of the record, and do this for 1700 rows.
This is for the Paradox database (yes I know it's old) and I have a simple SQL editor window to work with inside the application. I can select all the records I need to edit, grouped by their letter prefix.
Here's a view of the table:
UPDATE table
SET BookingID = SUBSTRING(BookingID , 3, LEN(BookingID ) - 2)
where substring(BookingID,0,1) ='B'

Access form fields for multiple Query parameters

I am using Access 2013.
I have one table,A form and a query in database.
I am trying create query to filter data in table using form.
I have added two fields(combobox) in form.
Both are referencing different columns.
And a button to trigger.
I am using this formula in Query for 'where' clause for one field(in Query)
[Forms]![frmDataEntry]![Transaction Type] Or IsNull([Forms]![frmDataEntry]![Transaction Type])
Its working fine if I select any value, its showing data matching that value.It's showing all records when I leave it blank.
But its not working if I add same formula(changing fieldname) for other parameter too.
Its showing correct data, if I select values for both comboboxes in form.But its showing blank dataset, If I ignore any combo box.
My expectation is:
If I select both values......It should filter matching both and get result.
If I select none.............It should show all records.
If I select only one.........It should filter based on only that column.
You could use in your WHERE clause this
Like IIf(IsNull([Forms]![frmDataEntry]![Transaction Type]),"*" ,
[Forms]![frmDataEntry]![Transaction Type])

Set default value for parameter in pentaho report designer

I am creating a report in pentaho report designer and need some help setting default values for a parameter that I've created.
One of the parameters labeled date fetches data from the date column of a table. While I am able to view all the dates in the drop down list, I am unable to find a way in which I can set the default value of this drop down to all (meaning all the dates together).
Is there a way in which I can set the 'all' value as default?
Assuming that you get the values for the filter from a JDBC connection in PRD, you can write a query like this. (I have used Postgresql).
This will load 'All' as the first values in the drop down and other distinct date values from your table. (Do the casting properly)
SELECT 1 AS sort,'All' AS date
UNION
SELECT DISTINCT 2 AS sort,
tablename.datecolumn::date AS date
FROM
tablename
ORDER BY sort
Then in your parameter that is shown to the user to select the date, enter All in Default Value field and select the query that we have written.
Next assuming that you use a KTR to retrieve data to your report, you can include the following query in a 'Table input' step,
(tablename.datecolumn IN (SELECT CASE WHEN('${date}' = 'All' OR '${date}' IS NULL) THEN tablename.datecolumn ELSE '${date}' END))
Hope this will help. If you have any further issues please comment below. Because this has worked perfectly for me.

Save All Results to Excel

I have run a query using Eclipse from a Sybase db. I need to eliminate duplicate entries but the results have mixed types - INT and TEXT. Sybase will not do distinct on TEXT fields. When I Save All results and paste that into Excel some of the TEXT field bleeds into the INT field columns - which makes Excel -Remove Duplicates tough to do.
I am thinking I might create an alias for my query, add a temp table, select the distinct INT column values from the alias and then query the alias again, this time including the TEXT values. Then when I export the data I save it into Word instead. It would look like this:
SELECT id, text
FROM tableA, TableB
WHERE (various joins here...)
AS stuff
CREATE TABLE #id_values
(alt_id CHAR(8) null)
INSERT INTO #id_values
(SELECT DISTINCT id
FROM stuff)
SELECT id, text
FROM stuff a
WHERE EXISTS (SELECT 1 FROM #id_values WHERE b.alt_id = a.id )
If there was a way to format the data better in Excel I would not have to do all this manipulation on the db side.I have tried different formats in the Excel import dialog..import as tab-delimited, space-delimited with the same end result.
Additional information: I converted the TEXT to VARCHAR but I now need a new column which has up to 5 entries per id sometimes. ID -> TYPE is 1-many? The distinct worked on the original list but now I need to figure out how to show all the new column values in one row with each id. The new column is CHAR(4).
Now my original select looks like this:
SELECT DISTINCT id, CONVERT(VARCHAR(8192), text), type_cd
FROM TableA, TableB
...etc
And I get multiple rows again for each type_cd attached to an id. I also realized I don't think I need the 'b.' alias in front of *alt_id*.
Also, regardless of how I format the query (TEXT or VARCHAR), Excel continues to bleed the text into the id rows. Maybe this is not a sql problem but rather with Excel, or maybe Eclipse.
You are limited in how much data you can past into an Excel cell anyway, so convert your text to a varchar:
SELECT distinct id, cast(text as varchar(255)) as text
FROM tableA, TableB
WHERE (various joins here...)
I'm using 255, because that is the default on what Excel shows. You can have longer values in Excel cells, but this may be sufficient for your purposes. If not, just make the value bigger.
Also, as a comment, you should be using the proper syntax for joins, which uses the "on" clause (or "cross join" in place of a comma).