select sum(DATEDIFF(“D”,M.ActiveStart,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) – 1, 0))) as Duration_Days , m.HomeBranch, m.LocationName from AX.Memberships M where m.ActiveStart < DATEADD(…
Trying to get Price Difference and Percent Difference
I am trying to find the daily price difference and the daily percent difference, in one field, in one table. Here is the code that I am testing. Here is a sample of my data (first three fields), with the expected results (last two fields named ‘PriceDiff’ & ‘PercentDiff’). I am usi…
Error in SSIS Package – There is a data source column with no name
I have a straightforward SQL statement that I posted into a DataFlow Task and got this dreaded error. There is no stored procedure or temp tables involved. What am I missing? The SQL works fine in SSMS and returns appropriate results. The query is pretty simple and I have never seen this error in SSIS before.…
What is Internal process of below mentioned queries?
As per performance which query is optimistic query? Answer id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra -: | :———- | :—- | :——— | :—– | :———— | :—— | :̵…
MySQL self join to find only the next revision
Actually I’m working with WordPress. I want to create a self-join or something similar to find a revision of a post, and the following revision of the same post. https://www.db-fiddle.com/f/eHnwYABYrVVQAhn8xLJ77q/1 The previous query doesn’t work since it takes, for every record of a, all the revi…
Syntax to resolve ORACLE error is ORA-01476: divisor is equal to zero
I’m using the NVL function to try and correct ERROR: Error fetching from cursor. ORACLE error is ORA-01476: divisor is equal to zero. I’m having trouble figuring out what the correct syntax is. Answer The normal method is nullif() in the dividend. So, instead of: You would use: Assuming that t.Amo…
How to Count How Many Zeros are within a column from the Right in Oracle SQL
I am currently going through a process of validating a column that holds reference numbers for each customer but they have to be a specific format to be counted as a genuine number. I initially …
Aggregate values at hourly interval using SQL server query
I have below test data in the table ID TEST_DATE Value 1 10/21/2019 0:00 10 1 10/21/2019 0:15 10 1 10/21/2019 0:30 10 1 10/21/2019 0:45 10 1 10/21/2019 1:00 …
how to export data from SQL in R
I’m a beginner in R. I have connection via ODBC to SQL DB: dbconnection
Sequence Numbering in SQL Server
I have an table (always ordered by ID ascending) with 5 records as such : ID Sequence 1 1 2 2 3 3 4 4 8 3 9 3 And the desired output is : ID Sequence 1 1 2 2 3 3 4 6 8 4 …