Using a property control to use unique values in a column for a Spotfire calculated column - properties

I am creating a calculated column (C) that uses a column property which is set through unique values in a column (B) which itself is set through a column selector. When I change the the data in this Column B (and column type remains the same) my calculated column (C) is not being updated appropriately. I know I am likely making a simple error but I can't figure it out.
Column B = [${Surface.Property}] #This property is set with a drop down menu where I choose which column (e.g., Column A or Column D (each have their own unique values but they are both strings)
Column C =
MostCommon(case when [Column B]="[${MyData}.{Column B}.{Surface.Selector}]" Then Min([Depth]) OVER (Intersect([Location],[Column B]))
else NULL
END) OVER (Intersect([Location]))
This series of calculations works perfect if choose Column A in the drop down menu "Surface.Property" which is use to set the column/values of Column B. However, when I change and select Column D as Surface.Property, the calculation no longer works. Im guessing this is the result of of "unique values" change but I'm not sure how to make this part of the calculation [Column B]="[${MyData}.{Column B}.{Surface.Selector}]", accept "new" values.
Any thoughts would help and hopefully this is somewhat clear!

Figured it out, it turns out I need to insert the column property into my calculated column As Value rather than As Text.

Related

Copying data from one column to another in the same table sets data to null in original column

I created a new column [LastLoginDate-NoTime] with the data type Date. I already have another column [LastLoginDate] that is of Datetime datatype.
Columns with the values
I am trying to copy values from the LastLoginDate column to the LastLoginDate-NoTime column using this query:
UPDATE [dbo].[SapUsersExt]
SET [LastLoginDate] = [LastLoginDate-NoTime]
But the problem I am having is that when I execute this query, it sets the data to null in the original column.
Screenshot: Error
I am also trying to convert the data from the LastLoginDate to just date format in the new column LastLoginDate-NoTime so that I can use it in my application. How would I do that?
I am trying to copy values from the LastLoginDate column to the LastLoginDate-NoTime column using this query
In that case, you're doing it exactly backwards - you should use this SQL instead:
UPDATE [dbo].[SapUsersExt]
SET [LastLoginDate-NoTime] = [LastLoginDate]
The first column - right after the SET - is the target column into which your values will be written.
The second column, after the = symbol, is where the data comes from (column or expression).
You had it backwards - setting the column with the actual values, to all NULL ....
This of course only works for a "one time" update - this will not keep your columns in sync over time, when new data is being inserted. For such a case, you'd need a computed column
ALTER TABLE dbo.SapUsersExt
ADD LastLoginDateOnly AS CAST(LastLoginDate AS DATE) PERSISTED;
or a trigger.
Or maybe, you don't even really need to actually store that date-only value - just use
SELECT
CAST(LastLoginDate AS DATE),
.......
if you need to date-only value from LastLoginDate

How to create a calculated column that computes the non-null value from one of two columns

I am creating a new database that requires a calculated column that pulls a percentage from one column (GrossMarginPercentage) and multiplies it by either an estimated value or an actual value column. Only one will contain a value and the other will be null.
Would any functions help me tell the new computed column what column (estimated or actual) to pull from and multiply by GrossMarginPercentage?
I tried:
Alter Table ChurnInfo
add DecMargin as case (when DecEstimated = 'Null' then
DecActual * GrossMarginPercentage else DecEst*GrossMarginPercentage end )
Solution: https://stackoverflow.com/a/56657223/11073192
I think you just want coalesce():
Alter Table ChurnInfo
add DecMargin as (coalesce(DecActual, DecEst) * GrossMarginPercentage);

Dynamic Way to Insert Data into SQLite Table When Column Counts Change

I am working on a script using SQLite where there is a flux in the number of columns that are available to be inserted into a table I am creating to later do a join on.
The table I am created to insert the data into has 97 columns, the data coming in from my feed can range from around 80 all the way up to that 97th column.
The error I get is SQLITE_ERROR: table allPositionsTable has 97 columns but 80 values were supplied and is the one I am trying to avoid by figuring out a way where this doesn't happen.
Are there any workarounds or tricks I can use to have SQLite function so that it will always include the columns where there is no data for them or dynamically not include them so the error goes away?
The error I get is SQLITE_ERROR: table allPositionsTable has 97
columns but 80 values were supplied and is the one I am trying to
avoid by figuring out a way where this doesn't happen.
This happens because you are using the default column list (i.e. by not specifying the columns into which the values are to be placed)
That is you would be coding the equivalent of INSERT INTO your_table VALUES(.......
so in the absence of a list of columns you are saying that you will provide a value for all columns in the table and hence the message when a value or values are not present.
What you want to do is use INSERT INTO your_table_name (your_comma_separated_list_of_columns_to_be_inserted) VALUES(.......
where your_table_name and your_comma_separated_list_of_columns_to_be_inserted would be replaced with the appropriate values.
See the highlighted section of the INSERT syntax that can be found at SQL As Understood By SQLite - INSERT
and the respective section from the above link is :-
The first form (with the "VALUES" keyword) creates one or more new
rows in an existing table.
If the column-name list after table-name is
omitted then the number of values inserted into each row must be the
same as the number of columns in the table.
In this case the result of
evaluating the left-most expression from each term of the VALUES list
is inserted into the left-most column of each new row, and so forth
for each subsequent expression.
If a column-name list is specified,
then the number of values in each term of the VALUE list must match
the number of specified columns.
Each of the named columns of the new
row is populated with the results of evaluating the corresponding
VALUES expression.
Table columns that do not appear in the column list
are populated with the default column value (specified as part of the
CREATE TABLE statement), or with NULL if no default value is
specified.

How to add a record into table, that is related to another table?

Good day!
I have two tables.
TABLE 1:
GENERIC [GE_ID / number] [GE_DATEIN / date] [GE_PERSON / number] + ...
TABLE 2:
WORKFORCE [WF_ID / number] [WF_NAME / text] [WF_SHIFT / number] + ...
Column [GE_PERSON] from table #1 is related to the column [WF_ID] from table #2 as many-to-one relationship. I have a simple form to add a data to the table #1 with several drop down boxes. One of these drop down boxes contains a list of names taken from table #2 (column [WF_NAME]) by SQL statement.
So when I am ready to add a record to table #1, I know the person name chosen from drop down box, but column [GE_PERSON] is numeric and I have to add a number equal to the column [WF_ID] which is pointing on name in table #2 (column [WF_NAME]).
QUESTION: how should I build the SQL statement (INSERT INTO) to make this work?
Thank you!
MS Access' combobox control allows the bound column to be hidden from the user while showing identifiable data columns that correspond to hidden field. See this section of MS tutorial. Once you do so, you will have a relevant number for your querying needs.
Brief steps to hide and set primary key as bound column:
For the [WF Names] combobox, include [WF_ID] in the Row Source query under Data tab of Property Sheet as first column:
SELECT [WF_ID], [WF_NAME]
FROM [WORKFORCE]
Under Data tab make [WF_ID] the bound column by placing 1.
Under Format tab, set Column Count to 2 (or more for each field in query) but give Column Width to first column nothing, something like: 0; 2
Now the combobox's value is the corresponding [WF_ID] of the selected [WF_NAME] in drop down list, so any query pointing to the control will be a valid number:
INSERT INTO [GENERIC] ([GE_PERSON])
VALUES (Forms!formname!WFNamesComboBox)
SELECT * FROM [WORKFORCE]
WHERE [WF_ID] = Forms!formname!WFNamesComboBox

Get values based on newly inserted value using SQL

I want to make filtration on a column after selecting a specific value of another column in the same table, I tried to use #... special character followed by the column's name to get the address of this value.
My SQL statement is like the following :
SELECT ATTRIBUTE FROM TABLE WHERE FIELD = '#FIELDNAME';
If I used a specific value instead of #FIELDNAME, it will work properly but it will be static but I need it to be dynamic based on the selected value.
Create another table which will have the list of values that are in the FIELDNAME and give each record a unique id ,then retrieve the value depending on what you have selected by the name of the new table's field preceded by '#...'
I don't know if that what are you looking for, please let me know.
If no triggers are allowed, do you have any date/time column in the table? Is it possible to have that extra column anyway to see the time of a newly inserted row?
You may have to check the lastest row entered, save its field value into a variable. Then do the select based on the variable value.
Based on the vague last row id you could try the following (it's not pretty). But again, if you have date/time that's more accurate.
select attribute from table
where field = (select field from table
where rowid =(select max(rowid) from table))
;
upate
Do you have the priviledge to set up your insert command as below:
insert into table (id, col1, col2,...) values (1,'something', 'something',...)
returning id into variable; -- you may either save field or id depending on your table
Then you may use this variable to select the records you want.