I have a table that houses information uploaded from a template (via another application). Well i noticed that the year was wrong (code in the application issue) and caused about 3000 lines of incorrect dates. My question is, how would i write a query to replace all the 20150101 (incorrect date) with 20160101 (correct date)? I am pretty sure its the UPDATE routine but i am not a SQL programmer so i am a tad lost. I am using latest SSMS.
Table: TRANS_USER_FORECAST_EDITS_FROM_EXCEL
Column Name: mo_day_year
DO A SELECT FIRST TO SEE HOW MANY RECORD YOU NEED TO UPDATE..
SELECT * FROM TRANS_USER_FORECAST_EDITS_FROM_EXCEL
WHERE mo_day_year = '20150101'
THEN COPY YOUR RESULT AND RUN THE QUERY BELOW TO UPDATE ALL THE RECORDS.
BEGIN TRAN
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL SET mo_day_year = '20160101'
WHERE mo_day_year = '20150101'
COMMIT
As you noted, it's indeed an update statement:
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL
SET mo_day_year = 20150101
WHERE mo_day_year = 20160101
Related
this is my code in PowerApps:
OnSelect = Patch(ProjectTrackerPowerApps, {ProjectTrackerID: First([#PowerBIIntegration].Data).ProjectTrackerID, 'Meeting Notes':TextInput1.Text } )
where ProjectTrackerPowerApps is the SQL table name, and "Meeting Notes" is the field in PowerApps that is being edited and the edits are to be read back to the SQL table using the OnSelect Code.
But it's not working, i.e. I don't see the changes in the SQL table.
I also tried this other code - slightly different than the 1st but it also didn't work:
OnSelect = Patch(ProjectTrackerPowerApps, defaults(ProjectTrackerPowerApps), {Field:Screen1.Selected.ProjectTrackerID})
Can you please review the code and help me correct so it works?
Thanks!
I've updated my coldfusion 2018 server with most recent update12 by Adobe. As soon as I've updated the server I've wrote some QoQ for my application with ORDER BY in my QoQ. Whenever I use order by in QoQ then the result data have some duplicate columns.
For my simple sample query as example,
<cfquery name="testRead" datasource="testmssql">
SELECT * FROM loginDetails
</cfquery>
<cfdump var="#testRead#" label="Main Query">
<cfquery name='readSub' dbtype="query">
SELECT userID, Username FROM testRead
ORDER BY userid DESC
</cfquery>
<cfdump var="#readSub#" label="QoQ Result" abort="true">
**Output:** Refer my image please.
Here you can see the second QoQ dump have two userID column. I'm not sure why we are having it here & where it's come from. ? If I add one more column in ORDER BY list then that column also get duplicated in result query. For example, If add ORDER BY userid DESC, userName then the query dump query having userID,userid,userName,username.
Note : It's not happening before my update12. And it's not happening for main query.
Any thoughts ? Please share. Thank you advance !.
This is a known issue with the update and a bug has been filed with Adobe. I would recommend you add a comment and vote for the bug.
Adobe Bug Tracker - CF-4212383
Duplicate columns with the same name in a Query of Queries which contains an ORDER BY clause.
Description from that bug:
Problem Description:
After applying CF 2021 Update 2, when using an ORDER BY clause in a QoQ, the fields in the ORDER BY clause have become case sensitive, and if they don't match exactly the case of the fields in the SELECT list, then a duplicate column is added to the resultant query, resulting in a query that has two (or more) columns with the same name.
Further, if no fields are added to the SELECT list and * is used instead, the fields in the ORDER BY clause must be upper case, otherwise duplicate columns with the same name (but different case) again appear in the resultant query.
This showstopping behaviour has been introduced in CF 2021 Update 2. CF2021 Update 1 behaves as expected. (CF2016 also behaves as expected).
Even though the bug mentions CF 2021 Update 2, it also affects CF 2018 Update 12. As verified by bug CF-4212430 submitted for CF 2018 Update 12 which was closed as a duplicate of the CF 2021 bug.
I have Dataset in PowerBI as below.
In PowerBI Desktop I want to filter records of below table based on condition described below.
ProjectName ReleaseDate UserReleaseDate
PROJ-1 12/09/2019 null
PROJ-2 null 02/02/2019
PROJ-3 07/07/2018 null
Date are in DD/MM/YYYY format.
I want to filter those records where
(ReleaseDate OR UserReleaseDate is IsInNextNYears(1))
You pretty much just do exactly what you described.
Table.SelectRows(YourTable, each (Date.IsInNextNYears([ReleaseDate], 1) or Date.IsInNextNYears([UserReleaseDate], 1)))
If you use any filter operation on a column in Power Query it will automatically create a Table.SelectRows step that you can edit to do what you want instead.
From
https://cloud.google.com/bigquery/docs/partitioned-tables:
you can shard tables using a time-based naming approach such as [PREFIX]_YYYYMMDD
This enables me to do:
SELECT count(*) FROM `xxx.xxx.xxx_*`
and query across all the shards. Is there a special notation that queries only the latest shard? For example say I had:
xxx_20180726
xxx_20180801
could I do something along the lines of
SELECT count(*) FROM `xxx.xxx.xxx_{{ latest }}`
to query xxx_20180801?
SINGLE QUERY INSPIRED BY Mikhail Berlyant:
SELECT count(*) as c FROM `XXX.PREFIX_*` WHERE _TABLE_SUFFIX IN ( SELECT
SUBSTR(MAX(table_id), LENGTH('PREFIX_') + 2)
FROM
`XXX.__TABLES_SUMMARY__`
WHERE
table_id LIKE 'PREFIX_%')
If you do care about cost (meaning how many tables will be scaned by your query) - the only way to do so is to do in two steps like below
First query
#standardSQL
SELECT SUBSTR(MAX(table_id), LENGTH('PREFIX') + 1)
FROM `xxx.xxx.__TABLES_SUMMARY__`
WHERE table_id LIKE 'PREFIX%'
Second Query
#standardSQL
SELECT COUNT(*)
FROM `xxx.xxx.PREFIX_*`
WHERE _TABLE_SUFFIX = '<result of first query>'
so, if result of first query is 20180801 so, second query will obviously look like below
#standardSQL
SELECT COUNT(*)
FROM `xxx.xxx.PREFIX_*`
WHERE _TABLE_SUFFIX = '20180801'
If you don't care about cost but rather need just result - you can easily combine above two queries into one - but - again - remember - even though result will be out of last table - cost will be as you query all table that match xxx.xxx.PREFIX_*
Forgot to mention (even though it should be obvious): of course when you have only COUNT(1) in your SELECT - the cost will be 0(zero) for both options - but in reality - most likely you will have something more valuable than just count(1)
I know this is a kind of an old thread but I was surprised why no one offers an answer using Variables.
"Héctor Neri" already mentioned this in the comments but I thought might be better to have an actual answer with a sample code posted.
#standardSQL
DECLARE SHARD_DATE STRING;
SET SHARD_DATE=(
SELECT MAX(REPLACE(table_name,'{TABLE}_',''))
FROM `{PRJ}.{DATASET}.INFORMATION_SCHEMA.TABLES`
WHERE table_name LIKE '{TABLE}_20%'
);
SELECT * FROM `{PRJ}.{DATASET}.{TABLE}_*`
WHERE _TABLE_SUFFIX = SHARD_DATE
Make sure to replace {PRJ}, {DATASET}, and {TABLE} values with your table location.
If you run this on BigQuery Web UI, you will see this message:
WARNING: Could not compute bytes processed estimate for script.
But you can see that variable properly reduce the table scan to the latest partition and does not cause any extra cost after running the script.
I use C++ Builder 6.0
I use TADODataSet execute following SQL statement:
SELECT Id, SUM(Saldo) AS Saldo
FROM Table
GROUP BY Id
I use this DataSet only for reporting. No need update date back to database.
When I try to modify field "Saldo"
adospCard->Edit();
adospCard->FieldByName("Saldo")->AsFloat=0.0;
adospCard->Post();
I get error:
Field 'Saldo' cannot be modified.
I add this line
adospCard->FieldByName("Saldo")->ReadOnly=false;
and error no more occurred, but field 'Saldo' has not changed.
adospCard->Edit();
//adospCard->FieldByName("Saldo")->AsFloat=1536.5
adospCard->FieldByName("Saldo")->AsFloat=0.0;
//adospCard->FieldByName("Saldo")->AsFloat=0
adospCard->Post();
//adospCard->FieldByName("Saldo")->AsFloat=1536.5
Howe to change ‘Saldo’ field value?
Add a calculated field to your dataset.
Calculate the right value for Saldo
in this calculated field (you can
use Saldo as source for it if you
want to)
display this calculated field in your report in
stead of the Saldo field.
Edit:
For examples of how to add calculated fields, see for instance here, here and here.
--jeroen
As ldsandon said, you cannot modify the "Saldo" field as it is computed.
If you need to set the value to zero when Id is "something" you are better off doing it in your query. The best approach depends on the criteria for setting the value to zero.
Or, save the results of the original query in a temp table then modify that before returning the results to the report.
Finally, what reporting tool are you using? Can that do the "Saldo = 0" change when rendering the report?
Consider storing your result in a ClientDataset - if you can be assured the result isn't too large.
I don't use "TADODataSet" so the following may not apply :)...
When I do the same (or similar) using my DB of choice (i.e. Advantage Database Server) I would use the INTO clause, albeit, with a TSQLQuery component (with the RequestLive property enabled). For example:
SELECT Id, SUM(Saldo) AS Saldo INTO #TempTable FROM Table GROUP BY Id