How can I enter an e-mail address with a comma in it into a cell? - sql-server

I'm trying to insert an email address with a comma in it (and it has to be entered that way) and I'm currently stumped on how to properly insert the exact text into this cell.
The e-mail address that needs to be entered as/is:
joe,.E.Blow#someemail.com
What I've tried is work different escape patterns into the code. For example, this...
'''joe'''+','+'''.E.Blow#someemail.com'''
gets entered into the database as...
'joe','E.Blow#someemail.com'
I've tried different combinations with single and double quotes and it can't even get past a simple parse without errors.
What is the best way to go about getting the email address entered as noted above? I know it's something simple but I'm just spinning my wheels here.

the solution is simple:
for example: joe,.E.Blow#someemail.com
SEE FIDDLE

Related

Get number of items in a field that contain specific text

i have a field that lists all email address and i want to get the number of all email addresses with a certain domain, for example, "mydomain.com".
I can do this with a scorecard and a filter but I need to do this with a custom formula so i can also get the average. My finial goal is to get the average of "mydomain.com" email addresses vs. the total.
I tried this
COUNT(CONTAINS_TEXT(profile.email, "#mydomain.com"))
But, of course, this does not work.
Maybe a COUNTIF?
Bottom lime, i need to figure out how to get the number of email addresses from a specific domain in to a variable so i can then do some math on it ;)
I hope this makes sense.
Thank you!
Everything I've read points to using a CASE statement, however I've not actually managed to get one to work.
Here's the documentation: https://support.google.com/datastudio/answer/7020724

SQL Server validating postcodes

I have a table containing postcodes but there is no validation built in to the entry form so there is no consistency in the way they are stored in the database, sample below:
ID Postcode
001742 B5
001745
001746
001748 DY3
001750
001751
001768 B276LL
001774 B339HY
001776 B339QY
001780 WR51DD
I want to use these postcode to map the distance from a central point but before I can do that I need to put them into a valid format and filter out any blanks or incomplete postcodes.
I had considered using
left(postcode,3) + ' ' + right(postcode,3)
To correct the formatting but this wouldn't work for postcodes like 'M6 8HD'
My aim is to get the list of postcodes in a valid format but I don't know how to account for different lengths of postcode. Is this there a way to do this in SQL Server?
As discussed in the comments, sometimes looking at a problem the other way around presents a far simpler solution.
You have a list of arbitrary input provided by users, which frequently doesn't contain the correct spacing. You also have a list of valid postcodes which are correctly spaced.
You're trying to solve the problem of finding the correct place to insert spaces into your arbitrary inputs to make them match the list of valid codes, and this is extremely difficult to do in practice.
However, performing the opposite task - removing the spaces from the valid postcodes - is remarkably easy to do. So that is what I'd suggest doing.
In our most recent round of data modelling, we have modelled addresses with two postcode columns - PostCode containing the postcode as provided from whatever sources, and PostCodeNoSpace, a computed column which strips whitespace characters from PostCode. We use the latter column for e.g. searches based on user input. You may want to do something similar with your list of Valid postcodes, if you're keeping it around permanently - so that you can perform easy matches/lookups and then translate those matches back into a version that has spaces - which is actually a solution to the original question posed!

Identify all strings in SQL Server code (red color - like in SSMS)

I was not able to solve this by myself so I hope I didn't miss any similar post here and I'm not wasting your time.
What I want is to identify (get a list) of all strings used in SQL Server code.
Example:
select 'WordToCatch1' as 'Column1'
from Table1
where Column2 = 'WordToCatch2'
If you put above code to SSMS all three words in apostrophes will be red but only words 'WordToCatch1' and 'WordToCatch2' are "real" strings used in code.
My goal is to find all those "real" strings in any code.
For example if I will have stored procedure 10k rows long it would be impossible to search them manually so I want something what will find all those "real" strings for me and return a list of them or something.
Thanks in advance!
The trouble is, Column1 is nothing particular different compared to WordToCatch1 and WordToCatch2 - not unless you parse the SQL yourself. You could modify your query to take the quotes away from Column1 and it will show up coloured black.
I guess a simple regex will show up all identifiers after an AS keyword, which would be easier than fully parsing SQL, if all the unwanted strings are like that, and its not just an example.

Treat Comma and Period as Decimal Separator in Navision Decimal Fields

I want to eliminate an error source, often happening in our company. In our country, we use the comma as decimal separator and a valid decimal number looks something like this: 85,32
The problem is, that the users sometimes press the period instead of the comma, because the keys are next to each other on the keyboard and they do not recognize their mistakes. Navision now formats the number entered 85.32 to 8.532,00 what leads to wrong data in our database.
I tried to set the AutoFormatType to 10 and the AutoFormatExpr to something like this <Integer><Point or Comma><Decimals> and I played around with some other values for AutoFormatExpr, but it still does not recognize the period as a valid comma separator. I even tried to format it afterwards at the OnValidate-trigger, but the AutoFormat logics of navision seems to come first and the value is already altered before the OnValidate field triggers gets executed.
I want to setup my page (or a specific decimal field in particular) that, no matter if the user types 85,33 or 85.33, the result should be 85,33.
Substitution way. Create a field on form(page) with SourceExpr of string type then parse it to whatever you like decimal format and save it to the real field.

Parsing text in Julia- Invalid ascii sequence

I'm trying to format a data file so that my other program will properly handle it. I am trying to handle the following data and I am getting a very weird error that I can't seem to put my finger on.
https://snap.stanford.edu/data/wiki-RfA.html
I am trying to format the data as [SRC TGT VOT], so I'd like the first two lines of my output file to be
1 2 1
3 2 1
because user 1 (stored in dictionary of users first) votes for user 2 with VOT 1 and then user 3 votes for user 2 with VOT 1. My problem is that when I try to run my code below, I always end up getting a very strange "invalid ascii sequence" error- can anyone help me identify the issue or perhaps find a way around this? It'd obviously be best if I could learn what I am doing wrong. Thank you!
Note, I understand that this is a bit specific of a question and I appreciate any help- I'm sort of baffled by this error and don't know how to resolve it at the moment.
f=open("original_vote_data.txt") #this is the file linked above
arr=readlines(f)
i=edge_count=src=tgt=vot=1
dict=Dict{ASCIIString, Int64}()
edges=["" for k=1:198275]
while i<1586200
src_temp=(arr[i])[5:end-2]
if (haskey(dict, src_temp))
new_src= dict[src_temp]
else
dict[src_temp]=src
new_src=src
src=src+1
end
tgt_temp=(arr[i+1])[5:end-2]
if (haskey(dict, tgt_temp))
new_tgt= dict[tgt_temp]
else
dict[tgt_temp]=tgt
new_tgt=tgt
tgt=tgt+1
end
vot_temp=(arr[i+2])[5]
edges[edge_count]=string(new_src)* " " * string(new_tgt)* " " *string(vot_temp)
edge_count=edge_count+1
i=i+8
end
Here we go - I'll write up my comment as an answer since it seems to have solved the question.
My hunch that the error stemmed from the fourth line (dict=Dict{ASCIIString, Int64}) was based on the fact that ASCIIStrings will error if you try to store non-ASCII characters in them. Since this file is coming from an international site, it's not unlikely that there are users with unicode characters in their names (or elsewhere in the data). So the simple fix is to change all instances of ASCIIString to UTF8String.
Just to make this answer a bit more complete, I downloaded the file and tried running the program. The simplest way to debug this is to run the script at top-level in the REPL and then inspect the program state after the error. After the error is thrown, i==3017. Now just try running each line of the while loop incrementally. You'll quickly see that line 3017 contains "SRC:Guðsþegn\n" — unicode, as I suspected. When you try to create a new entry in dict with that as the key, the error should have a backtrace to setindex! in dict.jl, where you'll see that it's trying to convert the key (a UTF8String) to an ASCIIString. So changing the dictionary type to have UTF8String keys solves the problem.
As it turns out, the edges array only contains strings of three integers (or sometimes a hyphen), so the ASCIIString there is ok, but still a little dangerous. I'd probably store that information in a more dedicated array of ints instead of converting it to a space-separated string: you know the first two elements in the string are ints, but the last element is unvalidated text from the file itself… which may be unicode or a space itself (which could mess up processing down the line).

Resources