Below is the table created and inserted values in it: Now I ran the following query: When you look at the query result, the last row of the Gender column has the value ‘Total’ in it. I want to replace ‘Total’ with ‘Grand Total’ only in the last row of Gender column while ke…
Tag: sql-server
How to generalize the JSON in stored procedure?
In my database, I have table called library which have columns like dependencies, email, alert, skipped and values are stored as I want to prepare JSON of these values which will look like as I have written have code as And my JSON doesn’t look like desired JSON I am not able to achieve correct json . C…
I want to get the updated Salary by EmpID
I have a column EmpID and Salary. I want to get the updated salary each EmpID. FIGURE 1 : ID EMPID Salary 1 00000 75000 2 00000 80000 3 00001 75000 4 00001 90000 5 00001 91000 6 00010 50000 7 00010 60000 8 00010 70000 This is my initial query that I created with specific EMPID 00000 : The
Split multiple strings in SQL
I am trying to split multiple columns of strings at the same time. My original data looks like: Table1 UserID Type ProductID 1 A, B 001, 003 and I want to end up with UserID Type ProductID 1 A 001 1 B 003 When I use I end up with this table that I do not want… UserID Type ProductID
SQL to fetch value of one column such that a certain value in another column does not exist
I have the following Table t key value 1 a 1 b 1 c 2 a 2 c In the above table, the Key 1 has three values i.e. a, b and c. However Key 2 has only two values i.e. a and c. How to write a SQL that would return the Key that does NOT have the value
Remove duplicate columns after using join on in sql
I have the following sql query that joins two select statements on two columns The query produces the following output. | Name | ItemNum |TicketNum |TicketNum |ItemNum | But I would like the output to be | Name | ItemNum |TicketNum | Answer Solution 1: Specify the column names like this Solution 2:
How can I join two tables on an ID and a DATE RANGE in SQL
I have 2 query result tables containing records for different assessments. There are RAssessments and NAssessments which make up a complete review. The aim is to eventually determine which reviews were completed. I would like to join the two tables on the ID, and on the date, HOWEVER the date each assessment …
Get same employeeid who belongs to different deptno at a particular interval
I am trying to list each employee who belongs more than one dept for a given period of time. Empid Dept Date 001 10 10/02/2022 002 20 10/02/2022 003 30 10/02/2022 001 20 10/02/2022 002 30 10/02/2022 001 10 11/02/2022 002 20 11/02/2022 003 30 11/02/2022 001 20 11/02/2022 002 30 11/02/2022 From the above source…
Query with Group and name sorting
I am trying to build a SQL query that is bit more complicated to what I am used to writing. Example data: So far I have a working query Currently it will return But I would like that query to always returns the names with biggest event_id, so good results would be “[Lpr] abc” and “[Lpr] Name…
How to display an individual with highest number of posts and an individual with lowest number of posts at the same time in SQL Server?
Below is the table I have created and I have also inserted values in it: Now I am trying to solve the following question: Write a query that displays the team members who have published the highest and lowest number of posts. This is what I have done: I received the following result: I almost got my desired r…