I have a simple query that I'm sure anyone whos not a novice will be able to easily solve, I have a table which has a bunch of 'tags' for instagram. I am trying to extract TAGS where DATE = today.
A rough copy of what I want is shown below, I know the syntax is incorrect which is why I'm struggling, but I think you can see what I'm trying to achieve, any advice welcome :)
ExecuteSQL
(
SELECT IGs::tag
FROM IGs::
WHERE IGs::creation date = 22/10/2048
;)
However I would prefer that creation date = $$todaysdate ( I will set the variable before the ExecuteSQL in the script.
You need to use quotes around the query. Something like this.
ExecuteSQL
(
"SELECT tag
FROM IGs
WHERE \"creation date\" = ?"
;"";"";$$todaysdate
)
Related
I am trying to build a fully parametrised pipeline template in ADF. With the work I have done so far, I can do a full load without any issues but when it comes to delta load, it seems like my queries are not working. I believe the reason for this is that my "where" statement looks somewhat like this:
SELECT #{item().source_columns} FROM #{item().source_schema}.#{item().source_table}
WHERE #{item().source_watermarkcolumn} > #{item().max_watermarkcolumn_loaded} AND #{item().source_watermarkcolumn} <= #{activity('Watermarkvalue').output.firstRow.max_watermarkcolumn_loaded}
where the 'max_watermarkcolumn_loaded' is a datetime format and the 'activity' output is obviously a string format.
Please correct me if my assumption is wrong and let me know what I can do to fix.
EDIT:
screenshot of the error
ADF is picking a date from SQL column 'max_watermarkcolumn_loaded' in this format '"2021-09-29T06:11:16.333Z"' and I think thats where the problem is.
I tried to repro this error. I gave the parameter without single quotes to a sample Query.
Wrap the date parameters with single quotes.
Corrected Query
SELECT #{item().source_columns} FROM
#{item().source_schema}.#{item().source_table}
WHERE #{item().source_watermarkcolumn} >
'#{item().max_watermarkcolumn_loaded}' AND
#{item().source_watermarkcolumn} <=
'#{activity('Watermarkvalue').output.firstRow.max_watermarkcolumn_loaded}'
With this query, pipeline is run successfully.
I am going to run a very simple query using python script. To make sure my script is working I am going to create a very simple .sql file with a simple query which does not depend on any other table.
something like: select currentDate
or something similar
You don't need a from clause in BigQuery. So something like this:
select 1 as x
or:
select current_date as curdate
I would suggest that you give the column a name so you can verify that you can access the column in your code.
Lets say I have a query like this:
Parameters Table_Name string, Field_Name string;
Update Table_Name Set Table_Name.[field1] = "new value", Table_Name.[field2] = "new Value" Where Table_Name.[Field_Name] = "Some value"
Basically I have the same query which I need to run against different tables which share some fields together. I want to be able to type the table name when I run the query.
I know this can be achieved with VBA, but this way would be a lot easier than VBA. Although VBA is also welcome but I would like to be able to do this in pure SQL.
How to achieve the above logic for table names AND field names?
Is this being done in MSAccess or in SQL Server? If you've got a SQL Server behind things, then you'll be looking to do some sp_executesql calls to get the job done. If you're doing this in MSAccess, you can accomplish the same by building dynamic SQL statements in VBA - either way would work if you've got Access pointing to SQL, though.
The following SQL I am trying to run is returning sql_string of "SELECT id FROM people WHERE id IN ("16")":
#ids = ["1", "6"]
sql_string = <<-SQL
SELECT id
FROM people
WHERE id IN ("#{#ids}")
SQL
Can someone please help modify the above query so it will create the sql_string of "SELECT id FROM people WHERE id IN (1, 6)"
Just throwing #ids in the query will concatenate the array and give you "16". You'll want to run #ids.join(',') to comma separate them. Plus you need to wrap the expression part of the string in #{}. Otherwise it will treat it as literal.
#ids = ["1", "6"]
sql_string = <<-SQL
SELECT id
FROM people
WHERE id IN (#{#ids.join(',')})
SQL
P.S. There are very few valid reasons for manually writing a whole SQL query in Rails. You should look into using ActiveRecord to do something like People.find_all_by_id(#ids) instead.
With the code fragment in one of the answers above, "#ids" is not sanitised. This is fine if your code 'knows' that "#ids" contains only valid integer IDs, but very dangerous if any ID came in from user input or a URL. See:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001831
...for a possible solution. This is a protected method so we have to call via 'send' to demonstrate its use at the console:
>> ActiveRecord::Base.send(:sanitize_sql_for_conditions, { :id => [1,6] }, :people)
=> "people.\"id\" IN (1,6)"
...i.e. insert the above result after the SQL WHERE keyword. As the previous answer says, unless you have a really complex case which can't be built up using standard Rails calls (which is indeed the case for Coderama but may not be for future readers), you should always try to avoid writing SQL by hand.
Bearing this in mind, an alternative way to build up complex queries is the "ez_where" plugin which is worth a look if anyone reading is thinking of resorting to SQL:
http://github.com/ezmobius/ez-where
I have a storedproc which has multiple select statement.
When it is executed in sql server , it returns multiple tables.
I need a query which will select a particular table from the storedproc e.g. sp_help.
Please help.
If i have a look at this link, it seems that it is not possible.
Astander is right. From the number of tables available in ur SP, it is not possible directly.
However, you can apply some trick to accomplish your work. I am giving an example here. May be you can generate some idea based on this line.
SELECT * FROM sys.Tables where name =
'my_tbl'
As you can make out that I am filtering out the query by a table among all the tables available in my database.
Something of this sort may help you.
Else, if can get the dataset and then from that get the needed datatable from ur frontend code.