I am trying to use Power Query to retrieve a value from SQL Server. I want to parameterize the table name. Like I want to use cell value from one sheet (Sheet1!A1 = Tablename1).
How do I achieve above condition in Power Query?
You may create named range table and refer to it:
= Excel.CurrentWorkbook(){[Name="table"]}[Content]{0}[Column1]
Or use parameter table:
https://www.excelguru.ca/blog/2014/11/26/building-a-parameter-table-for-power-query/
Related
I would like to know a way of adding one additional column to a BigQuery table, that will populate all the rows for this newly created column with specific constant value.
I know how to create column with NULL values:
ALTER TABLE project_id.dataset.table
ADD COLUMN A STRING
But my goal is to also add the ingestion time with CURRENT_TIMESTAMP() function. Is it even possible with one command? Or maybe I need to apply subsequently some second command?
Seems like a solution is to use another query after the mentioned one:
UPDATE project_id.dataset.table SET A = CAST(CURRENT_TIMESTAMP() AS STRING) WHERE 1=1
I'm stacking on some issue on Tableau when I'm trying to run Custom query with string parameter. I'd like to query one column dynamically from certain table on BigQuery.
My SQL looks like.:
select <Parameters.column for research> as column,
count(*) as N
from table_name
where date=<Parameters.date>
group by 1
Here I'm trying to use parameter as column name.
But unfortunatlly I'm receive string column with one value of the parameter.
Is it possible to execute my request? If it's doable, so how to write the Custom SQL?
In application I am working on.
I have to input from user through excel and first put it in temporary sql table & then from temporary table to final target table.
My query is failing while putting data from temporary table to target table.
Because some values present in temporary table are out of range of columns in target table.
How can I check if values present in temporary table are within range of column of target table?
I have to check like this
20 < len(temporary_table.column1) < 50
or is there any better way
If you are using SQL server you can use below query for data checking.
temporary_table.column1 between 20 and 50
If you are looking based on the column max length. For example, your columns have datatype varchar(100) then you can use the condition like this
where len(temporary_table.column1)<=100
Extending on the above answer you can just use col_length instead of hard coding the value on the target column. This makes it more automated and less prone to mistakes (entering a value mistakenly)
where len(temporary_table.column1) <= COL_LENGTH ( 'target_table' , 'column1' )
I have a table validationmaster with a column called vrformula. It contains a formula like:
pf > 1
In that pf is one of the column names in the datasource table. I have to check whether pf of all the entries in the datasourse table is > 1 or not, but I don't know how to make it work.
I can fetch that formula correctly but Sql Server considers that formula as a string, I don't know how to change that whole expression into a formula.
For example: select * from datasource where meterid=4716 and pf>=1 is the statement I want to execute, with that formula at the end of the where clause being generated from the vrformula column.
You'll have to use Dynamic SQL.
This is probably obvious, nevertheless, a quick and dirty solution is to execute a SELECT for retrieving the column value, then executing a second SELECT containing the condition.
Here I assume that you are executing the SQL statements from a code written in a programming language (not SQL).
I have a hopefully pretty simple question here. I'm converting some Access SQL script into Server Management Studio 2008.
Currently the Access script shows the following line of code:
IIf([rsosourceID]) IN (254,360,446),"MoneySavingExpert" as SourceName
Basically it's creating a temporary table with four columns, if the fields match say those 3 numbers on the left then it will populate a fourth column with their new name. (To be used for grouping in a later report)
How can I do something simillar in SQL? I've tried using a Case statement but to my knowledge that will only alter the field you're looking against.
In this case I need to look at one field then using it's results alter another, any ideas?
A case statement can return a new column using the value of any other column(s):
SELECT rsoSourceID,
rsoDescription,
rsoCategory,
case when rsoSourceID in (254,360,446)
then 'MoneySavingExpert'
else null end as SourceName
FROM TableName