I need to calculate the mode average by clinic. Test data as follows: Clinic Test2 A123 2 A123 3 A123 4 A123 3 A123 3 B123 2 B123 2 B123 2 B123 2 B123 2 B123 4 I can show the mode for all clinics using However, I want the mode per clinic, not all clinics. What I really want
Tag: sql-server
How to select all parents of a child from a table
I am using SQL Server. My table is called Employees. It looks like this: I am trying to build a query that returns all parents of the children So the query would return the parents of Bin and Sam are I tried this but wasn’t successful but this can only work for 1 parent How can I get the whole
Query SQL Server From Specific Time On Previous Date To Specific Time On Current Date
Sorry for the noob SQL question. I have a table in SQL with a DateTime column. I need to run a script daily to show any lines from 8am yesterday until 8am today. So for example, today I would run: I also know that I could run this, but this will only give me the previous day through the current
Microsoft SQL Server – Convert column values to list for SELECT IN
I have this (3 int columns in one table) I would like to run such query with another someTable: where 1,2,3 are list of INTs converted to a list that I can use with SELECT * NOT IN statement Any suggestions how to achieve this without stored procedures in Micorosft SQL Server 2019 ? Answer If you want rows in
Identify the pattern to get desired output
We have below table contains multiple code against the ID and CounterID. Need an output based on code and id. Condition: Against the ID and CounterID case 1 : if there is code CI and CO then no record case 2 : if there is code CI and CO and CI then last record with code CI case 3 :
A better way to obtain SQL data than I am currently using
I need to retrieve data from an external SQL Server database and view it (not store it) in my ASP.NET MVC application. The only way I can connect to the server is by using a server name, port number and access to a SQL Server stored procedure that the server owners provide. Currently the only way I know how t…
Displaying multiple database tables in one table
I have multiple databases with the same table (an Eventlog with different values). The names of these databases are subject to change. I am trying to display the Eventlog tables in one consolidated table with the corresponding database name. I tried to using cursor and dynamic SQL statement to achieve this wi…
SQL Query Challenge. Divide by Subquery returning ‘Subquery returned more than 1 value.’ error
I have the following table in which I have two sales orders and each sales order has a different number of transactions. SaleOrder Transaction Amount Tax Delivery Charge TotalTax (Including Tax of Delivery Charge) S1 T1 12 0 3 5.5 (This also includes Tax in Column 4) S1 T2 27 4 3 5.5 S2 T1 15 2.5 5 6 S2
Dynamic columns using pivot
I have a table that looks like this: Main table id bomname styleid 1 bom1 101 2 bom2 102 3 bom3 103 this is detail table Id bomId bomKey bomValue 1 1 part cllr 2 1 unit kg 3 1 qty 123 4 1 part body 5 1 unit kg 6 1 qty 456 7 2 part slm 8 2
Order by 6 digit to 7 digit value then from lowest to highest
This code attempts to sort my values by number of digits, from 6 to 7, then from lowest to highest numerically. I have sets of data in my table and I always get: ID 992425 992199 1001111 I expect result ID 992199 992425 1001111 How to sort by number of digits, from 6 to 7, then ID from lowest to