I have an output in my queries that gives me:
xxxxxxx xxxxxxxxx : 123456 (xx) - xxxxxxx...
or
xxxxxxx xxxxxxxxx : 12345678 (xx) - xxxxxxx...
basically text before either a 6 or 8 digit number then text after
I've created a column in a table in SSRS that just shows the number, and I used this expression:
=Mid(Fields!my.Value,InStr(Fields!my.Value,":")+1,Instr(InStr(Fields!my.Value,":")+3,Fields!my.Value," ") - InStr(Fields!my.Value,":") -1)
Which now gives me an output of 123456 or 12345678. Which is great.
However I'd like to do an additional thing. I'd like to create an output that if the digit is 6 numbers long returns London and if the digit is 8 numbers long then it returns Paris . Is this possible - I've researched and tried with:
=IIF(Len(Mid(Fields!my.Value,InStr(Fields!my.Value,":")+1,Instr(InStr(Fields!my.Value,":")+3,Fields!my.Value," ") - InStr(Fields!my.Value,":") -1))=8,"Paris",IIF(Len(Mid(Fields!my.Value,InStr(Fields!my.Value,":")+1,Instr(InStr(Fields!my.Value,":")+3,Fields!my.Value," ") - InStr(Fields!my.Value,":") -1))=6,"London","Wrong Number"))
But sadly that just gives me 'wrong number' so I'm close but no cigar. I'm sure this expression just needs a final tweak but can't quite get there. Any help appreciated.
Looks to me like your best and easiest solution is to use the Len function on the value in the actual textboxes using ReportItems!. I'd also recommend using the TRIM function to cut out any unintended spaces that could skew your Len count.
Rather than repeat the same expression to isolate the number, you should be able to simplify the second expression like the following.
=IIF(Len(Trim(ReportItems!CodeTextbox.Value)) = 6, "London",
IIF(Len(Trim(ReportItems!CodeTextbox.Value)) = 8, "Paris", "Wrong Number")
Related
I have a query where i am trying to update field by taking the left number of characters before a space.
I'm not very good with Access VBA, so I'm trying to do this via a query.
my data is a list of SKUs, where I want to update the same field (sku) with a shorter SKU number, by using the Left$ function along with the InStr function to take all characters to the left of a space in the number.
test sku
E349CAJ6 OBROBRO
E357CAJ6 OBROSID
E329CAJ6 OWHIBRO
E358CAJ6 ONO SID
Note that the space isn't always in position 9, sometimes it varies. I was trying to use the following Query update value: Left$([IMPORT - EFF ORDERS]![SKU], InStr([IMPORT - EFF ORDERS]![SKU]," ",1))
The InStr, identifies the starting position based on the space, to use for the Left function.
The SKU field is a Short Text type field.
However, when I run the query, I get a "Type Conversion" error and none of the records will update.
I have wracked my brain to try to figure this one out and would appreciate an expert's fresh eyes on it.
Thank you so much in advance !
The ,1 is in wrong argument, really don't need it. If you want to use Compare argument then also use Start argument. Without explicit Start and Compare parameters, function will use defaults.
Left([IMPORT - EFF ORDERS]![SKU], InStr(1, [IMPORT - EFF ORDERS]![SKU], " ", 1))
InStr() in this case is returning a value that will be used as a length parameter, not a starting position. Start position for Left is first character.
Consider the string "55,33,255,66,55"
I am finding ways to count number of occurence of a specific characters ("55" in this case) in this string using mysql select query.
Currently i am using the below logic to count
select CAST((LENGTH("55,33,255,66,55") - LENGTH(REPLACE("55,33,255,66,55", "55", ""))) / LENGTH("55") AS UNSIGNED)
But the issue with this one is, it counts all occurence of 55 and the result is = 3,
but the desired output is = 2.
Is there any way i can make this work correct? please suggest.
NOTE : "55" is the input we are giving and consider the value "55,33,255,66,55" is from a database field.
Regards,
Balan
You want to match on ',55,', but there's the first and last position to worry about. You can use the trick of adding commas to the frot and back of the input to get around that:
select LENGTH('55,33,255,66,55') + 2 -
LENGTH(REPLACE(CONCAT(',', '55,33,255,66,55', ','), ',55,', 'xxx'))
Returns 2
I've used CONCAT to pre- and post-pend the commas (rather than adding a literal into the text) because I assume you'll be using this on a column not a literal.
Note also these improvements:
Removal of the cast - it is already numeric
By replacing with a string one less in length (ie ',55,' length 4 to 'xxx' length 3), the result doesn't need to be divided - it's already the correct result
2 is added to the length because of the two commas added front and back (no need to use CONCAT to calculate the pre-replace length)
Try this:
select CAST((LENGTH("55,33,255,66,55") + 2 - LENGTH(REPLACE(concat(",","55,33,255,66,55",","), ",55,", ",,"))) / LENGTH("55") AS UNSIGNED)
I would do an sub select in this sub select I would replace every 255 with some other unique signs and them count the new signs and the standing 55's.
If(row = '255') then '1337'
for example.
I have these rows :
ROW 1 containing: How to .405
ROW 2 containing: How to 405
When i use the contains query such as :
Contains( FIELDNAME, '"405"' )
Or this query :
Contains( FIELDNAME, '"405*"' )
I got only the ROW 2 but not the ROW 1 because of the period.
I tried creating an empty stoplist and assigned it to the fulltext, it does not work.
I tried the FREETEXT query, it does not work also.
What is weird is when i add one caracter more to the value of ROW 1 (How to .405M), it works....
How to return also the ROW 1 when querying with only "405" ?
Thanks
Well, a bit old question but:
You did not tell what language you are using, so I will assume you are using english.
That happens because .405 is treated like a number. In English, .405 is a decimal value meaning 0.405. So the ft search will try to find numbers with 405 in the decimal part of them. Ft will also try to find rounded numbers similar to .405.
You should check my question: sql-server-2008-fulltext-rounding-money-value
This probably has something to do with my understanding of full text search or perhaps a known issue. My Java code creates search term for full text search on MySQL like this -
+word*
This works fine if the value in the DB column contains more text than the word itself. However, if the value is exact - no result are returned. I expected it to return results when value is an exact match. Let me give an example -
Assume that DB has column name with value "Manish", now if I search with this -
+Manis*
It does return the result correctly, but if I try this -
+Manish*
It doesn't return any result, though exact match exists in DB column - Name. How can I obtain the desired behaviour in both these cases? Removing + sign works, but it returns far too many results when there are two or more words.
Any help, pointers would be highly appreciated! I am using MySQL 5.0
TIA,
- Manish
Try removing the +
+Man searches for Man but not Manish
Man* searches for Man and Manish.
I have the following query:
SELECT `admin_users`.*
FROM `admin_users`
WHERE (avatar REGEXP 'avatars/Name-[0-9]+.jpg+')
ORDER BY `admin_users`.`avatar`
DESC LIMIT 1
It's ok if I have something like:
avatars/Name-5.jpg
avatars/Name-6.jpg
But if I have, avatars/Name-15.jpg, for example, it doesn't return in query.
In other words, It only works for 1 digit, not for more. How can I solve it?
When comparing strings (an that is what avatar is), "avatars/Name-1..." comes before "avatars/Name-5..." simply because the string "1" comes before "5".
It is not practical to order those by an embedded number. This would do what you want, but it is pretty cryptic:
ORDER BY 0 + MID(avatar, 14)
To explain
MID will start at the 14th character of 'avatars/Name-15.jpg' and extract '15.jpg'.
0+ will take that string, convert it to a number and deliver the number 15. (When a string is turned into a number, the first characters are taken as long as it looks like a number. So, 0+'abc' will deliver 0, since there is nothing at the beginning of abc that looks like a number.)
If the left part were not exactly 14 characters in all cases, the trick will fail. And it may get so complicated as to be 'impossible' in SQL.