|
|
|
|
|
|
|
Question of the Day |
Today's question (by Kendra Little): | |
DBCC Meaning | |
What does "DBCC", as in (DBCC SHOW_STATISTICS) stand for? (Pick the answer defined in the current Microsoft documentation on DBCC) | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by Kathi Kellenberger) |
The "Median" Function There are many aggregate functions available in SQL Server. Which function can be used to calculate a median? Answer: PERCENTILE_CONT Explanation: According to Microsoft, the PERCENTILE_CONT function "Calculates a percentile based on a continuous distribution of the column value in SQL Server. The result is interpolated and might not be equal to any of the specific values in the column." This function can be used to calculate a median when the numeric literal parameter is 0.5. Here's an example from AdventureWorks which returns a list of years and the median TotalDue: SELECT DISTINCT YEAR(OrderDate) AS OrderYear, PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY TotalDue) OVER(PARTITION BY YEAR(OrderDate)) AS MedianOrder FROM Sales.SalesOrderHeader; (Note: DISTINCT is used because this function will return the answer for every row in the results.) PERCENTILE_DISC is similar, but it will return an actual value from the data and not interpolate the result. It does return the median when applied to an odd number of rows. There is no MEDIAN function in T-SQL, but it is possible to create a custom CLR function. The AVG function returns the average, which is not the median. |
Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
SQL Server 2017 - Administration |
Procedure master..xp_cmdshell - Msg 15121, Level 16, State 10, Procedure master..xp_cmdshell, Line 1 [Batch Start Line 2] An error occurred the execution of xp_cmdshell. A call to 'CreateProcessAsUser' failed with error code: '1314'. working on migrating from SQL Server 2008R2 to 2017 when creating proxy account and running xp_cmdshell using sqlserver login I am getting the error […] |
SQL Server 2017 - Development |
Table locks while inserting into the table - Hi , I am facing a deadlock while i am trying to insert data into a table. At the same time we have app users working on the application , which inserts data in our table. SO, in order to avoid deadlock , can i use table lock? if so , which table lock to […] |
Data Extraction Tools - Currently using SQL Stored Procedure to write a script joining multiple to form a data and insert into another table. Is there any other data extraction tools can replace above? |
SQL Server 2016 - Development and T-SQL |
How to add unique row numbers if there is a duplicate records in sql server - Hi All, I am looking for a way to add unique sequence number to my result set in sql server even though there is duplicates or not. For Example, If first 3 rows are duplicate rows then the sequence should be 1 instead of 1,2,3. Then if the 4th,5th row is duplicate then sequence should […] |
Development - SQL Server 2014 |
bcp hold the csv files and doesnot write to the csv file - Hi, The following is sql statement set @sql = 'bcp xxxxx.dbo.CsvTemp out D:/EDI/INCOMING/test1.csv -c -t, -T -SDBNAME' DBNAME - server name.. which is part of a stored procedure SP1. When i call this SP1 from .net website... BCP utility just creates the file at the location , doesnot write anything to it and holds the […] |
SQL 2012 - General |
How to write loop below with best practice performance ? - I work on SQL server 2012 I have temp table get data from excel and based on data exist on excel i insert on table inside loop temp table always have big amount of data may be at least 5000 or 10000 or 15000 or more I need every iteration increased by 5000 rows insert […] |
SQL Server 2012 - T-SQL |
Date Range Dynamic Column count in sqlserver - dear All Above format, I need sql server Query |
SQL Server 2019 - Development |
Country Shape Files and STIntersect - A friend of mine asked me a really interesting question... Imagine a flight path (I guess a linestring of (Longitude, Latitude) points)… I'm trying to figure out all the countries a flight would overfly. I could do it with STIntersect and STBuffer (to give myself some margin for error). But where do I get the […] |
Inline and Multi-statement table-valued functions - When you run an inline or a multi-statement table-valued function, either type of function will return a table. Is that table a temporary table? Does that table have local scope or global scope? If #2 is yes, how can you control if the table returned will have local scope or global scope? |
Reporting Services |
How to export a report to Word from Visual Studio 2019? - I installed Visual Studio Enterprise 2019, Version 16.44 in my PC (Windows 10). I also downloaded and installed SQL Server Reporting Services Projects separately and successfully. I made a SSRS report in my Visual Studio successfully. However, I don't know how to export my SSRS report to Excel and Word. I can't find any web […] |
SSRS Parameters OLEDB - Hi I am using OLEDB to connect to an Oracle. I have two parameter which I want to use in my dataset query. What should I put for the parameter. Dataset Query: Parameter positions are indicated as YearParameter and MonthParameter SELECT DATA_FACT2.HMO_ID, DATA_FACT2.HRS_AUTH, DATA_FACT2.HRS_PAID, DATA_FACT2.Year, DATA_FACT2.Month, DATA_FACT2.RPT_TYPE FROM DATA_FACT2 WHERE (DATA_FACT2.Year = YearParameter) AND (DATA_FACT2.Month […] |
Powershell |
Get Secondary replica name in a variable - I need to pass secondary replica name in a variable to a command for example I get the primary replica name using Get-DbaAvailabilityGroup -SqlInstance ListenerName| Select-Object * -ExpandProperty PrimaryReplicaServerName How do I get the secondary replica name? Thanks |
Strategies and Ideas |
Adding a column to a Type 2 SCD - Hello, I have a standard type 2 SCD that is performing well however the business have asked for additional info that needs to be added to the DIM. My issue is that if I add a column, it will set all existing rows to not current and insert a new row for all thus doubling […] |
Integration Services |
Conditional split variable - All, I'm trying to use a variable in a conditional split condition. I tried a few combinations similar to the following: CreationDate >= (DT_DBDATE)"01/01" + [@$Package::Year] && CreationDate < (DT_DBDATE)"01/02/2019" The year parameter contains a four digit year. Would someone mind advising the correct syntax? I did some searching but with no success. Thanks |
Microsoft Access |
Find and Copy Data from Another Table - Hi: I want to update DOB in Customers table from Info Table Two tables Customers ID, Name, DOB, Blood Type Info ID, DOB Scenario ======== Find where ID of “Customers” = ID of “Info” then copy “DOB” from Info to “DOB” Customers Note: there is data already in DOB of Customers, i want to update […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |