I am trying to do a LEFT JOIN to merge a table and view and the right table has duplicate items(usernames). I want to keep them but add another column to mark them as isDuplicate=’TRUE’. I wanted to use CASE WHEN EXISTS but can’t get it to work correctly, it produces wrong results: Ideally I…
Tag: sql-server
How to type Degree symbol (°) in Azure SQL data warehouse
I have data source like this: 1°18’19.74″N But when I insert it to Azure data warehouse it look like this: 1�18’19.74″N
use Enddate to generate Months(Dates) to Enddates in SQL
I have a table as below: I want to generate from the table above to return ID, Enddate, MRR and Month as shown Note the Month column of example ID = 2 consist of next month up to the enddate. The same applies to ID of 3 and 5. However, ID 1 and 4 Has NULL because we are in
SQL Server Multiple Rows into One row
I have a table with lot of records. I provided a sample of 1 record (4 rows) Need the rows to be combined as follows How can this be achieved? Answer You can use aggregation: Note that the data you describe sounds like it comes from an aggregation query. Usually this is more easily fixed by fixing that query …
SQL SERVER: Reset running total according to two conditions
I need to reset the running total when two conditions are met. See update below for clarification. Using SQL SERVER UPDATE 1: The Data: The data is partitioned by item number and ordered by the week of the year. Therefore, Item_Number = the item number. Cartons = the number of cartons sold that week per item …
Getting different results from LIKE query and stored procedure for (starts and ends with) search
I am trying to implement a stored procedure that gets the two parameters @startsWith and @endsWith and constructs this query string: @startswith + ‘%’ + @endsWith To search for entries of a single …
RECURSIVE QUERY – PARENT/CHILD
Say I have a table like so: id Parentid childid ——————————– 01 null 02 02 01 03 03 02 04 …
T-SQL Group By summarize fields using logical functions
How can I aggregate and arrive to these results? Answer Assuming the columns actually contain the literal string values ‘TRUE’ and ‘FALSE’, we could use:
SQL Server Migration and Encryption issue
I have a bit of a quandary that I could use some help with. We are in the process of migrating a SQL Server 2014 Enterprise edition to from on-premise to an AWS SQL Server 2017 Enterprise system. The current system contains both TDE and Symmetric Key Encryption for column level encryption. This is where the f…
How can I make this code work on SQL Server
I was wondering why my SQL code isn’t working properly on SQL Server while when I upload it on phpmyadmin it works perfectly. Is it some difference between those SQL’s? Is someone able to make this code working well on SQL Server? I’ve posted only part of database but with your help I’…