How do I trim values or text that are selected in a ComboBox on an Access Form - sql

I have a ComboBox on an Access 2007 form.
I created a table that holds text values that feeds into the ComboBox.
The text is too long so I would like the text to become trimmed to the last 5 characters
when any value is selected.
Example: In the ComboBox is: My Favorite Color is Green - 10001
But if the user select Green, I only want to insert the code 10001 in the query using trim.
How do I trimmed the values/text that are selected so that only the code is passed on to the rest of the query?
PARAMETERS [Forms].[ExampleForm]![cboColor] Text ( 255 );
SELECT FavColor
FROM COLOR
WHERE FavColor IS NOT NULL
HAVING (MAX(FavColorCode)=Forms.ExampleForm!Right(Trim([cboColor]),5))
I am getting an error message of Undefined Function.
Thanks everyone!
Guy

Just a tip, may be:
PARAMETERS [Forms].[ExampleForm]![cboColor] Text ( 255 );
SELECT FavColor
FROM COLOR
WHERE FavColor IS NOT NULL
AND (MAX(FavColorCode)=Right(Trim([Forms].[ExampleForm]![cboColor]),5))
Your SQL Statement was incorrect, try this now

It looks like #Luka showed you how to use those functions correctly with the value from cboColor. However, after fixing that part of your query, I suspect the db engine will throw a different error:
You tried to execute a query that does not include the specified expression 'FavColorCode' as part of an aggregate function.
I think you need to either do something else instead of the HAVING clause, or add a GROUP BY clause and an aggregate expression to your SELECT fields list. However I don't know how to fix the query because I don't understand what it's supposed to do.

Related

SSRS - Need to hide column inside a group

I have a requirement to hide a column, if no value exits in that column. But i have a grouping(Parent : Employee Number, Child: Category) in the report. In some of the group result may have value, but some of then does not have.
Example screen shot attached.
If you check the above image, second employee(Shiju) does not have Category. So for the second employee(Shiju) - need to hide Category column.
I tried with "Column Visibility" option and Column Groups > select Column > write expression in "Hidden" property. Following is the expr.
=iif(CountDistinct(Fields!Cat.Value) = 0,True,False)
These two options did not work.
Please give any solution for this.
Thanks in advance.
Your expression is almost correct, you just need to format the 0 else it will treat it as nothing:
=IIF(CountDistinct(Fields!cat.Value)=cint(0),true,false)
The other thing to check is that the field is actually null or nothing rather than blank strings or spaces.

Count in Expression Builder in Access

I have a Query named Data and it has 5 fields A, B ,C ,D, E. The Field A has always distinct values. I have form with where I have an unbound textBox. Through the Expression Builder for the text box. I use Count([Data!A]). When I go to the form view it shows me #Error.Where as the count in Query Data is 20. Where am I going wrong with the syntax?
It should read:
Count([Data]![A])
or just:
Count([A])
You can use
=DCount("Name_of_your_field";"Name_of_your_table")
In your unbound textbox if you don't absolutely need the query.

Replace null with zero in crosstab query in Telerik

I just created 2 cross table using wizard function of Telerik Standalone report designer tool
since ISCED 5 has values for private and public its showing properly
using same query I created second cross tab and
but since ISCED 6 table doesnt have values for "public" section its showing like this
how to show as zero for public section 2nd cross tab (when no values for specific row)
You should modify the value of the field using an expression to evaluate your condition.
Select the textbox containing the data corresponding to the column you like to format when the value is null.
In the property pan on the right select "Value"
Write in there your expression, it should be something like this:
=Iif(Fields.MyField IS Null,"0",Fields.MyField)
You should also consider if the value instead of null is empty and eventually cover this case in the expression if applicable.
= Iif(Fields.MyField IS Null OR Fields.MyField = "", "0", Fields.MyField)
More information on conditional formatting can be found here.
Let us know if this works for you.

access query no result

Can some one tell me what is wrong with this query as I run this query and refer combo box value on the form but it is not returning any value?
SELECT [2G_KPI].CSSR
FROM 2G_KPI
WHERE ((([2G_KPI].CSSR) Like [Forms]![Form1]![segment_name].[Text]));
In ComboBox you there are 3 things, selectedValue , SelectedIndex and Selected text
Based on how you have coded,debug and check what value goes in the "predicate of your where clause".

How can I create a blank/hardcoded column in a sql query?

I want have a query with a column that is a hardcoded value not from a table, can this be done? I need it basically as a placeholder that I am going to come back to later and fill in.
example:
SELECT
hat,
shoe,
boat,
somevalue = 0 as placeholder
FROM
objects
then I would loop through this query later and fill in the placeholder
in this example someValue is not a field in objects, I need to fake it. I am doing this in coldfusion and using two datasources to complete one query. I have tried the space() function but have been unable to get it to work.
Thanks.
SELECT
hat,
shoe,
boat,
0 as placeholder
FROM
objects
And '' as placeholder for strings.
This should work on most databases. You can also select a blank string as your extra column like so:
Select
Hat, Show, Boat, '' as SomeValue
From
Objects
For varchars, you may need to do something like this:
select convert(varchar(25), NULL) as abc_column into xyz_table
If you try
select '' as abc_column into xyz_table
you may get errors related to truncation, or an issue with null values, once you populate.
The answers above are correct, and what I'd consider the "best" answers. But just to be as complete as possible, you can also do this directly in CF using queryAddColumn.
See http://www.cfquickdocs.com/cf9/#queryaddcolumn
Again, it's more efficient to do it at the database level... but it's good to be aware of as many alternatives as possible (IMO, of course) :)
SELECT
hat,
shoe,
boat,
0 as placeholder -- for column having 0 value
FROM
objects
--OR '' as Placeholder -- for blank column
--OR NULL as Placeholder -- for column having null value
Thank you, in PostgreSQL this works for boolean
SELECT
hat,
shoe,
boat,
false as placeholder
FROM
objects