how to get name of the month Bigquery [duplicate] - google-bigquery

This question already has an answer here:
In bigquery, can you specify a language when using format_date - Localization in date functions
(1 answer)
Closed last year.
I need to get name of the month on Bigquery but in different languages .
my code : select FORMAT_DATETIME("%B", DATETIME('2022-01-04'))
get it only in english.
thank you.

There is no localization for date functions in BigQuery. You have a couple of options: write a function to replace the month names with the languages you'd like. Or, create a translation table with the English names and names you need, then join on that to display the desired language.

Related

I'm currently looking for a dynamic way to convert rows to columns in a specific way in SQL server [duplicate]

This question already has answers here:
T-SQL dynamic pivot
(5 answers)
Closed 6 years ago.
I'm currently looking for a dynamic way to convert rows to columns in a specific way in SQL server (I was able to do it in excel vba but the excel limitations made me go to SQL).
Abstract : I am making a daily analysis over 10 years considering 1315 stocks, for each stock we have daily returns for a period going from 29/12/2009 to 30/12/2016.
As you can see every 2614 row there's a new stock with the 3 following rows showing text..
Table on SQL
And I would like to obtain this result.. therefore looking for a good insight to help me go through this!
Desired solution draft
I am doing this for a quantitative department in Luxembourg to implement a dynamic model allocation of smart betas. (First time with SQL)
Thank you for your help! feel free to ask any questions if you need any other detail..
R.H.
This is also known as a dynamic pivot -- for sql server see https://stackoverflow.com/a/10404455/1327961

Week of year of a timestamp using derby/JavaDB

I need to know the week of year of a timestamp using Derby/JavaDB. And to make it worse I have to extract it from a parameter not a column. Don't ask why but that should be a minor problem.
On DB2 I say someting like
VALUES WEEK_ISO(?)
But how do I get the same result with Derby aka JavaDB?
Thanks Bryan, your Link was very helpful.
http://therealdanvega.com/blog/2010/02/17/creating-apache-derby-custom-functions-part-2
It seems there is no week function in derby but it is very easy to program such a function yourself. Especially when you use it from Java.

View with parameters in BigQuery

We have a set of events (kind of log) that we want to connect to get the current state. To improve performance/cost further, we would like to create snapshots (in order to not check all the events in history, but only from the last snapshot). Logs and snapshots are the tables with date suffix.
This approach works OK in the BQ, but we need to manually define the query every time. Is there any way to define 'view' with parameters (e.g. dates for the table range query)? Or any plans to do something like that?
I know that there are some topics connected with TABLE_RANGE / QUERY in views (eg Use of TABLE_DATE_RANGE function in Views). Are there any new information on this subject?
That's a great feature request - but currently not supported. Please leave more details at https://code.google.com/p/google-bigquery/issues/list, the BigQuery team takes these requests very seriously!
As a workaround i wrote a small framework to generate complex queries with help of velocity templates. Just published it at https://github.com/softkot/gbq
Now you can use Table Functions (aka table-valued functions - TVF) to achieve this. They are very similar to a view but they accept a parameter. I've tested and they really help to save a lot while keeping future queries simple, since the complexity is inside the Table Function definition. It receives a parameter that you can then use inside the query for filtering.
This example is from the documentation:
CREATE OR REPLACE TABLE FUNCTION mydataset.names_by_year(y INT64)
AS
SELECT year, name, SUM(number) AS total
FROM `bigquery-public-data.usa_names.usa_1910_current`
WHERE year = y
GROUP BY year, name
Then you just query it like this:
SELECT * FROM mydataset.names_by_year(1950)
More details can be found in the oficial documentation.
You can have a look at BigQuery scripting that have been released in beta : https://cloud.google.com/bigquery/docs/reference/standard-sql/scripting

SQL: Splitting first, last and middle name into their own columns? [duplicate]

This question already has answers here:
Splitting the full name and writing it to another table in SQL Server 2008
(2 answers)
Closed 9 years ago.
How would I go about splitting one column that has the first, last and middle name. To there own separate columns in a SQL Server 2008 query?
The column is called NAME
NAME(char(25),null)
Mctasrren ,David Max
Cressler ,Patti L
Basil ,Vessen Eddie
Chapplestait ,Victoy
this is what i've used so far my main issue is the middle name. or if someone has a better way to shorten the first name code.
--last name code
left([NAME],charindex(' ,',[NAME]))
-first name code
substring([NAME],charindex(',',[NAME])+1,charindex(' ',substring([NAME],charindex(',',[NAME])+1,25-charindex(',',[NAME])+1)))
Do you want to split it into columns as part of a result set, create computed columns on the table, or actually update the schema to have the data split in the source?
In any case the basic nuts and bolts can be done by either:
Use a combination of CHARINDEX, SUBSTRING, and LEFT or RIGHT to find commas or spaces and split around that. If you sure you data will always be 'L_NAME ,F_NAME M_NAME_OR_INITIAL' that will pretty easy. I am actually I surprised I didn't find an similar question here near the top of a google search, but there is an example of similar from SQLServerCentral.
Use a RegEx via the CLR, which can be more robust if there is any variety in the data. If you are familiar with RegEx this should be a straight forward parse. Again, a simplified example can found on MSDN.
Whatever you choose, you'll probably quickly run into names that don't easily follow that format. In that case you want to build more logic into a function handle different types of names.

Situation with SQL query [duplicate]

This question already has answers here:
How to search for a comma separated value
(3 answers)
Closed 8 years ago.
I have data in table in below format
id brand_ids
--------------
2 77,2
3 77
6 3,77,5
8 2,45,77
--------------
(Note the brand ids will be stored like comma separated values, this is common for values in this field)
Now i am trying to get a query which is capable of querying out only rows which have '77'
in it..
I know i can use LIKE command in three formats LIKE '77,%' OR LIKE '%,77,%' OR LIKE '%,77' with or condition to achieve it. But i hope this will increase the load time of the sql.
is there any straight forward method to achieve this? if so please suggest.
Thanks,
Balan
A strict answer to your question would be: no. Your suggestion of using LIKE is your best option with this data model. However, as mentioned, it is highly suggested that you use a more normalized model.