I am writing a query and I want it to do a order by a series. The first seven records should be ordered by 1,2,3,4,5,6 and 7. And then it should start all over. I have tried over partition, …
Tag: sql-server
STRING_SPLIT in TSQL on MS Server creates list with repeating values. WHY?
I am using 2017 MS SQL Express. The following code creates this erroneous result. Any clues why? SELECT BNAME, LIC_STRING INTO dbo.SEPARATE2 FROM dbo.together CROSS APPLY STRING_SPLIT(LIC_STRING, ‘,’)…
How to group this table properly?
Here’s my dataset with expected out. But I am having issues doing it. Also, I attached the query I created and the output is not correct. could you please point me to where my mistake is? DROP TABLE …
SQL Server – Remove some numbers in a string contains numbers
I have a column contains string with numbers formatted as comma delimiter. I want to write an update query to update those numbers in the column based on the numbers to be removed that provided, but I …
SQL window function with date filter
Looking to do a LAG/LAST_VALUE/MAGIC window function on a table which somehow needs to include a date filter (as in how far back it should go). I’m trying to get the value as of 7 days ago onto every …
How to select user ID who has saved the most products and the list of products he has saved
I am trying to query the user ID who has saved the most products and the list of products he has saved +—————-+———+ | Saved products | user_id | +—————-+———+ | A …
How to order by column minus first character in a select distinct statement
I need to organize a query based on a column in sequential order in a select distinct statement. The select distinct statement concatenates a character onto the front of a number (i.e “S1”, “S2″…”…
How to count/increment the current number of occurances of a table column in a MS SQL select
I have a table which looks like this: id | name| fk_something —————- 0 | 25 | 3 1 | 25 | 2 2 | 23 | 1 and I want to add another column with a number which increments everytime row …
SQL query not showing the right result when using LIKE
I am using Microsoft SQL Server Management Studio 2018 for my queries and I am trying to get the total quantity of ‘Cavity’ part types for each order and I have notice some anomaly for 1 order. I am 99% sure that it has been properly added to the SQL database as each order is first created in Acce…
SQL Server : select first occurrence from two columns
(Edit: I am bound to use Visual Studio 19 and have no rights to install any other application) I have a small SQL table with about 150k rows and 20 columns which I need to modify. I need the table to be ordered by date. I need the first occurrence of a value from two columns. Depending on if the