As part of our testing process, I’m trying to automate the following: Drop DatabaseB. Create a backup of DatabaseA Recreate DatabaseB from the backup of DatabaseA I had hoped something like this would work RESTORE DATABASE DatabaseB FROM DISK = ‘c:tempDatabaseA.bak’ WITH REPLACE, but that tu…
Tag: sql
INSERT value by adding URL and file name
I want to to insert value into my single column with website URL and upload path. But I’m really don’t doing that. Here I have 2 columns into my table. And I want to insert the website URL and upload …
Recursivly call on a lagged value in the same column, Or Have two interdependent columns
The first query does not run because I have a SUM() inside a LAG() which is just illegal but I’ve included it just to conceptualize the idea. Or Now I should mention there is are two null columns, result and CumRes, in “ready_set” which is why the second query even runs. Here is the exact id…
How to find duplicate records in MySQL, but with a degree of variance?
Assume I have the following table structure and data: I’d like to be able to find duplicate transactions where the description and amounts match, but the date would have some degree of variance +/- 3 days from each other. Because the “Burger King” transactions are within three days of each o…
SQL Syntax – Section in MERGE Statement
It’s been a while since I’ve worked in a T-SQL environment. I previously worked for Google, and, of course, they had their own special flavor of SQL. Now that I’m back, I’m reading back up on my T-SQL features. I understand the MERGE statement (at least, I think I do!), but I was looki…
SQL function to generate new row per event?
I’ve looked for an answer here to no avail; wondering if this problem is best suited outside SQL environment but thought I’d see how it could be solved. I’m trying to look at web journeys and as a result need my data to be in the following format: At present the data is in the following form…
Snowflake Failed to cast variant value “{TIMESTAMP VALUE}” to TIMESTAMP_NTZ
Above is the copy statement that I have made. But I keep getting the following error “Failed to cast variant value “2020-09-265T08:03:42.358Z” to TIMESTAMP_NTZ” Answer There’s a problem with the input data: September 265 is not a date. If you want to parse that date to null, you …
Query with join from MSSQL to Oracle
I have this query which runs on MsSQL: How do I convert it to work with Oracle data base type? Answer The only change is to drop the as: Oracle doesn’t support as for table aliases.
BigQuery producing negative (!) zero when numeric 0.0 multiplied with negative numerics/integers
I intend to do a CSV export directly from BigQuery, using the bq CLI (with flag –format=csv). I run into an issue where if a column with a numeric value is multiplied with a negative one, BigQuery returns -0.0 (whatever that means) and this causes issues in the importing system of this CSV file. Example…
Counting values within the same row in SQL Server
My SQL Server problem is as follows: let’s say we have clients and we wish to rate them based on 4 categories (Score_1…Score_4) on a scale of 0 to 2. I have a table presented below: What I want my code to do is count the number of 0, 1, and 2 values each of my clients recieved. The result