Concatinate part of two columns - sql

select name,(name,1,3||phone_no,1,3)from users order by (name);
I'm writing a query for the above problem and it is showing error.
Write a to display user name and password. The password should be generated by concatenating first three characters of user name and first three numbers in the phone number and give an alias name as the password. Sort the result based on user name

remove extra parenthesis and use substring function
select name,substr(name,1,3)|| substr(phone_no,1,3) from users order by name

Related

PostgreSQL/Metabase: How to create variable to filter by multiple numbers

I would like to filter by multiple ids (e.g. item ids of purchases). The following line of code does not seem to do the trick either for number or text variables (e.g. user names). How should I write this line of code so in the filtering field I could type my values separated by a comma and look for entries that contain either of the item ids I have provided? How would that line of code differ if wanting to apply a filter by a text variable instead (i.e. user name)?
[[where "User name" like concat('%',{{user_name}},'%')]]
Use a field filter parameter, mapping it to the id column and it's respective table
Then structure your query like below:
select * from profiles where user_name ({{PARAM}})
Documentation: https://www.metabase.com/learn/sql-questions/field-filters

Teradata Character Column with non alphabet values

I have a name column in Teradata that has customer full name all in one column. There are some names with -,_,.,/,#,! in between the name characters. I want to be able to pull records where there are names with these conditions. Is there a better option to pull records with the scenario below?
Currently, I am writing query like this
SELECT NAME FROM TABLESOURCE WHERE NAME LIKE ANY('%-%','%.%','%#%','%~%','%!%')
Thanks in advance.
I haven't tested this but I think you could test for equality when those characters are removed from the name using otranslate
select name
from tablesource
where name <> otranslate(name,'-.#~!','')

Select statement in SQL Server returns null while fetching values using email in where; unable to fetch data using values with dots using select

I'm trying to get password from email address but the problem is that the selection query won't read the the values after dots in the emails column and returns null results. I've tried PARSENAME() and RIGHT() functions to get it read the full email address. But no luck there. I've put my query statement below.
select Password
from Faculty
where Email = 'john.carson#outlook.com'
I'm not getting the password that belongs to that email address, instead all I get is null. The datatype is both email and password fields are nvarchar(100). And there are 5 records with different emails one of which is this. I'm sure the problem's rising because of the dots, because I tried using dummy data in email as like johncarson#com and I got the password respective to that. I'm using SQL Server as my database engine.
I Hope, It will be work
select Password
from Faculty
where Email like 'john.carson#outlook.com'
I checked with dummy data but it's working please check with Like clause may be any space is exists in Email field.
Declare #Faculty Table (Email Varchar(300),Password varchar(20))
Insert into #Faculty VALUES ('john.carson#outlook.com','123'),('john1.carson#outlook.com','12335'),('john2.carson#outlook.com','12356')
select Password
from #Faculty
where Email = 'john.carson#outlook.com'

split string with specific character

Here is my situation
there is a column that comes from csv file, i loaded all fields properly in sql but in email column, i have more than 1 email address for some records.
if it would be 2 emails, i could handle but as long as i have 3-4 or more emails, then i have little problem.
here is an example
'ekuntsche#addictionsuisse.ch;ekuntsche#suchtschweiz.ch;ekuntsche#sfa-ispa.ch;ekuntsche#addiction-info.ch'
this is only 1 column, i need to split them to 4 different column as email1,email2,email3,email4 and delimiter is ';'
I think i should use charindex and substring etc. but i could not create it.
if someone can create a function and show how to run the function, that would be super helpful.
thank you
database name 'bi_deploy'
main column name is 'email'
unique id for this table is 'ID'
(this is only email table, every row will have 1 email address, i can make it actually, but i could not split emails properly)

Access Data Type Mismatch on my SQL Code

I have a query that pulls the phone extension and the full name of a person from my phone system import, and splits the full name into a First and Last name. It is working great for spliting the name up but if I try to sort by either name I get a Data Tyep Mismatch Error.
Here is the SQL Code.
SELECT ExportG3R.Extension,
Left([ExportG3R.name],InStr([ExportG3R.name],",")-1) AS LastName,
Trim(Mid([ExportG3R.name],InStr([ExportG3R.name],",")+1,Len([ExportG3R.name])-InStr([ExportG3R.name],","))) AS FirstName
FROM ExportG3R
ORDER BY ExportG3R.Extension;
Any ideas on how to get this working?
I created a ExportG3R table with text fields for Extension and name. Your query worked with name values like "Litzner, Mike". However, a name value which doesn't include a comma, such as "Litzner Mike", gave me #Error for LastName and "Litzner Mike" for FirstName. And if name is Null, it gives me #Error for both. Neither of those was a deal-breaker for SELECT until I tried to sort on LastName and/or FirstName. When attempting those sorts, the Access 2003 db engine responded "Invalid procedure call", which is not the same error message you're getting.
So, although I'm not certain my situation exactly matches yours, I'll suggest you try your query with a WHERE clause to return only rows which have non-Null name values and also include a comma.
SELECT
e.Extension,
Left(e.[name],InStr(e.[name],",")-1) AS LastName,
Trim(Mid(e.[name],InStr(e.[name],",")+1,Len(e.[name])-InStr(e.[name],","))) AS FirstName
FROM ExportG3R AS e
WHERE e.name Like "*,*"
ORDER BY ORDER BY 2,3;
Another concern is that name is a reserved word. When creating that table in design view with Access 2007, gave me a warning about that field name. Try creating a throw-away table in Design View and read the help it offers when it gives you a warning about name. If at all possible, change it to something which isn't a reserved word ... FullName perhaps.
Finally I think this would be simpler if the name field were split into two fields in the table itself. Storing names as "Last, First" combines 2 attributes in one field. So when you need either of them, you must split them out. It's easier to store them separately, then concatenate them whenever you need them as "Last, First":
SELECT LastName & ", " & FirstName AS FullName
you could wrap it in a sub query;
SELECT extension,lastname,firstname
FROM (
SELECT ExportG3R.Extension,
Left([ExportG3R.name],InStr([ExportG3R.name],",")-1) AS LastName,
Trim(Mid([ExportG3R.name],InStr([ExportG3R.name],",")+1,
Len([ExportG3R.name])-InStr([ExportG3R.name],","))) AS FirstName
FROM ExportG3R
) order by firstname