How to return first letter of a word in Access - vba

I have been trying to return the first letter of a last name in Access.
I tried this in a query but it shows an error message.
In my table I have a field called lastName.
When I make a new query and open the expression builder I use the following expression:
Example: Left([lastName],1)
It shows the error that it is invalid.
How do I make this work?

Microsoft's Help on String Functions shows that you should be using the following format:
=Left([SerialNumber],2)
If [SerialNumber] is “CD234”, the result is “CD”.
I took a quick look at a few different languages, and they all showed the same format. None of them used a semicolon (;) in place of a comma (,).

Related

How to dynamically format BigQuery `dataset.schema.table name` with backticks

I need to work through how to take stored procedure functions from
region-us.INFORMATION_SCHEMA.ROUTINES
and modify the backticks that default to coming through around the project and place them around the dataset.schema.table()
The reason is more for uniform results across our system than a technical error need.
currently when I run this query
SELECT
replace(ddl, 'CREATE PROC', 'CREATE OR REPLACE PROC'),
FROM region-us.INFORMATION_SCHEMA.ROUTINES
where lower(routine_type) = 'procedure'
It will return the below:
`project-data-sandbox`.schema.MySP()
`project-data-sandbox`.schema.YourSP(MySP)
`project-data-sandbox`.inv.partnumber(orderid)
`project-data-sandbox`.inv_part.part_number(part_id)
I have tried the below query
SELECT
REGEXP_REPLACE(ddl, r"project-data-sandbox`.", "project-data-sandbox.") AS replaced_word
, REGEXP_REPLACE(ddl, r'`([a-zA-Z]+(-[a-zA-Z]+)+)`\.[a-zA-Z]+\.[a-zA-Z]+\(\)','Apples') tester
FROM region-us.INFORMATION_SCHEMA.ROUTINES
where lower(routine_type) = 'procedure'
I get part of what I want. However, the problem is our stored procedures can be named any sort of names and they could require objects to be passed to them.
I added the tester column to see if I could replace the project string with another word (or regex) but it isn't even replacing it with apples yet.
which I would want turned into this:
`project-data-sandbox.schema.MySP`()
`project-data-sandbox.schema.YourSP`(MySP)
`project-data-sandbox.inv.partnumber`(orderid)
`project-data-sandbox.inv_part.part_number`(part_id)
I'm working through Regexp_replace but I'm having difficulty figuring out how to get the backtick between the parenthesis and the last letter.
Thanks for any help!

SQL request to find item in table by value in column

Its pretty simple question, I know, but I really stacked with a problem with it...
I have a table customer_customer and a column code in it. So I need to find all items with a specific code value. So I wrote that:
SELECT * FROM customer_customer WHERE code LIKE "КL-12345"
and got an error:
column "КL-12345" does not exist
Why КL-12345 became a column if I specify it as value of code column? What am I doing wrong?
String literals must be enclosed in single quotes.
By enclosing it in double quotes, you specified a variable name.
Also, note that your where condition is the same as writing
where code = 'КL-12345'
LIKE is used for pattern matching. For instance you would match all codes that contain 'KL-12345' like this
where code like '%KL-12345%'
Change it to single quotes
SELECT * FROM customer_customer WHERE code LIKE 'КL-12345'
or
SELECT * FROM customer_customer WHERE code = 'КL-12345'

Syntax error in expression of SSRS

I have two datasets in my report and data is being displayed through a table. When I give expression like below:
=Format(Fields!InvDt.Value, "dsRepSalesReport_tblPrintSalesReport","dd/MMMyyyy")
It says there is Syntax error. If I remove dsRepSalesReport_tblPrintSalesReport part, there is no error.
1) Please advise how to wite the expression in format with aggregate expression.
2) If I write expression without dsRepSalesReport_tblPrintSalesReport part, my table repeats data and shows for all invoice. But when I add aggregate part, dsRepSalesReport_tblPrintSalesReport
Table just shows one value several times.
Please advise how to handel with these two issues.
Thanks
The method signature for Format is:
Public Shared Function Format(
ByVal Expression As Object,
Optional ByVal Style As String = ""
) As String
So that means you can't just specify the field and the Scope as in your first example; the first of the two arguments must return one value only.
In your example, you could use something like:
=Format(First(Fields!InvDt.Value, "dsRepSalesReport_tblPrintSalesReport"), "dd/MMMyyyy")
Which will format the first value in the specified Scope.
Another option would be to just set the value as required in the report then use the Format property:
It's difficult to answer your second question without knowing what your data/required results are... If you update the question with some simplified sample data to illustrate the actual issue you're facing that would be helpful.

linqpad ; expected

I'm trying to run the following as a "C# expression"
Directory.GetDirectoryRoot( #"C:\Users\DMORIN\Documents\Penguino\Shelves\session").Dump();
I get the error "; expected"
If I copy and paste that into an existing example query (replacing the example) it works.
eg. If I replace the contents of "Readme.First()" with the code above, things work. If I make a new query with language "C# statements" I get the error.
F4 and check your Additional Namespace Imports.
You can get the error if, for example, you have a space in there eg System Windows Forms instead of System.Windows.Forms.
And you will need to save it back as the default for new queries if there is a problem.
When you use C# expression, LinqPad expects an expression, not a statement.
You need to remove the ; at the end of the line.

Removing Spaces in Calculated Lists

I have created a calculated column which creates a URL which calls a Column called "Pitch Name" and from that will create the URL but I have to remove the space/spaces between words from pitch which needs to be displayed as a URL. Example of this is "Coca Cola" needs to be "CocaCola" so the site name can be"http://sitename.com/CocaCola". I've tried using the TRIM function but that doesn't work. I have tried the REPLACE function aswell but that seems not to work either. Any Solutions?
(Taken from an attempt to edit an answer:)
Update: The REPLACE and FIND Functions work but only if the string contains the amount of the desired character. And if the character doesn't appear the same amount of times the formula has asked for you will always get the string #VALUE which means it hasn't worked
SharePoint Calculated Fields use Excel functions, not .NET functions, so you probably want to use SUBSTITUTE rather than REPLACE.
Try something like this:
=SUBSTITUTE([Pitch Name], " ", "")
Update:
According to Xue-Mei Chang in Calculated Field Error:
The "SUBSTITUTE" function is not available in SharePoint.
As a workaround, he proposes:
For the "SUBSTITUTE" function, you have to use a combination of the "REPLACE" function with a "FIND" function. The "FIND" would return the position of the desired character in the string, which would then pass on to the "REPLACE" function so it can replace it with the new character.