I need to get how many of a specific hour have occurred between two dates in TSQL. Some examples: The following would give the result = 1 declare @date1 datetime = ‘2019-10-01 00:00:00.000’; declare …
how to select distinct values from a table when i need to select values having y if it has both y,n values and n values only if there is no y value
i have a table with data like promo flag ab21 y ab21 N bc22 N bc22 N CD23 Y CD23 Y ef24 N ef24 y i want distinct promo ,flag from the table but when …
Understanding window functions to deduplicate records while retaining true changes
I asked this in dba stack exchange but haven’t had any luck. Cross-posting. SQLFIDDLE I am close to figuring this out but I’m just stuck at a wall. I’m attempting to understand a post by Aaron …
How do I count distinct events over sequential seconds?
I have a database with multiple columns, date, timestamp (HH:MM:SS), and phone numbers. I am trying to find a way to find unique calls in sequential seconds. For Example: Date Timestamp …
How to avoid code repetition with PHP SQL prepared statements?
In most examples of SQL PHP prepared statements that I see, such as: $sql = ‘INSERT INTO tasks(task_name, start_date, completed_date) VALUES(:task_name, :start_date, :completed_date)’; $stmt = $this-&…
VB.Net Function Return MySql Results Two Dimensional Array
The following code pulls data from a MySql connection and returns the array (output). This two dimensional array only works when the number of rows and columns are specified before running the query. …
How to make a query that brings the results of the day
I have this query but I want to bring the results processed on the day and if there is no data in excess on the day bring the last 100 processed. SELECT * FROM tbl_classe where classe>= ‘2019-10-…
How to add characters in the results up to certain length in SQL
I need to add * symbols to make all records to 15 digits. What is the best way? Thanks, Answer Your other questions are tagged for SQL Server, so I will assume that database. SQL Server does not support rpad(), but you can use left() and replicate(): or: If col is not already a string, then you need to cast
How to move decimal places in SQL
I want to place a decimal between the first and second digit of the interest rate and keep 2 trailing after the decimal. How do I go about doing this? SELECT TOP 10 l.PARENTACCOUNT AS [Account Number]…
SQL – add blank column and populate based on value in calculated datediff column
I am very very new to SQL and also self taught….so be clear please. I’m trying to add a blank column within my Data that will show if the number in the days column is: Between 15-21 AS 15-21 days ,…