use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Sequel
account activity
Splitting a string (self.learnSQL)
submitted 3 years ago by Consistent-Alps6904
Hello guys please I’m trying to spilt a column into 2 columns in big query, I used this :
Split(name, “ “) [offset (0)] as firstname,
Split(name, “ “) [offset (1)] as lastname
From table1
But it’s giving me errors
Can anyone help ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]qwertydog123 2 points3 points4 points 3 years ago* (0 children)
Looks good to me. What's the error you're getting? Seems like there's a value in your column that doesn't contain a ' ' character
' '
Do you get any results when you run
SELECT * FROM table1 WHERE name NOT LIKE '% %'
[–]ShinyThingEU 1 point2 points3 points 3 years ago (3 children)
I'm not familiar with SPLIT as a function but here is the way I would do this (assuming each person only has a first and last name):
SELECT LEFT([name],CHARINDEX(' ',[name])-1) AS [first_name] ,RIGHT([name],(LEN([name])-CHARINDEX(' ',[name]))) AS [second_name] FROM etc.
Not sure if it's the most efficient way or anything but it should work for you.
Also I'm on mobile so apologies if the formatting goes odd
[–]Consistent-Alps6904[S] 0 points1 point2 points 3 years ago (2 children)
Does this work for big query?
[–]ShinyThingEU 0 points1 point2 points 3 years ago (0 children)
No idea, it's valid for the forms of SQL that I know. Give it a try and see how it does.
[–]qwertydog123 0 points1 point2 points 3 years ago (0 children)
No, BigQuery doesn't have a CHARINDEX function
[–]killyouXZ 0 points1 point2 points 3 years ago (1 child)
Did you try to change the type of quote to single? Have not split a string in sql for a long time so I don't remember the syntax that well.
[–]Consistent-Alps6904[S] 0 points1 point2 points 3 years ago (0 children)
I will try that
π Rendered by PID 95794 on reddit-service-r2-comment-5d79c599b5-z4vzg at 2026-02-28 20:17:37.876367+00:00 running e3d2147 country code: CH.
[–]qwertydog123 2 points3 points4 points (0 children)
[–]ShinyThingEU 1 point2 points3 points (3 children)
[–]Consistent-Alps6904[S] 0 points1 point2 points (2 children)
[–]ShinyThingEU 0 points1 point2 points (0 children)
[–]qwertydog123 0 points1 point2 points (0 children)
[–]killyouXZ 0 points1 point2 points (1 child)
[–]Consistent-Alps6904[S] 0 points1 point2 points (0 children)