Laden...
|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Further Defining the Window Clause | |
I have defined a window in SQL Server 2022 as follows: SELECT SUM(sod.OrderQty) OVER() AS Total FROM Sales.SalesOrderDetail AS sod WHERE sod.ProductID IN (710, 711, 712) WINDOW ob_OrderID_ProductID AS (ORDER BY sod.SalesOrderID, sod.ProductID) In the SUM() aggregate, I want to partition the data. Which of these statements is the way to make a more detailed window over() clause? A: SELECT SUM(sod.OrderQty) OVER(ob_OrderID_ProductID partition BY sod.SalesOrderID) AS Total FROM Sales.SalesOrderDetail AS sod WHERE sod.ProductID IN (710, 711, 712) WINDOW ob_OrderID_ProductID AS (ORDER BY sod.SalesOrderID, sod.ProductID) B: SELECT SUM(sod.OrderQty) OVER(ob_OrderID_ProductID partition BY sod.SalesOrderID) AS Total FROM Sales.SalesOrderDetail AS sod WHERE sod.ProductID IN (710, 711, 712) WINDOW ob_OrderID_ProductID AS (ORDER BY sod.SalesOrderID, sod.ProductID), pb_SalesOrderID_ob_OrderID_ProductID AS (PARTITION BY sod.SalesOrderID ORDER BY sod.SalesOrderID, sod.ProductID) C: SELECT SUM(sod.OrderQty) OVER(partition BY sod.SalesOrderID ORDER BY ob_OrderID_ProductID) AS Total FROM Sales.SalesOrderDetail AS sod WHERE sod.ProductID IN (710, 711, 712) WINDOW ob_OrderID_ProductID AS (ORDER BY sod.SalesOrderID, sod.ProductID) D: SELECT SUM(sod.OrderQty) OVER(partition BY pb_SalesOrderID ORDER BY ob_OrderID_ProductID) AS Total FROM Sales.SalesOrderDetail AS sod WHERE sod.ProductID IN (710, 711, 712) WINDOW ob_OrderID_ProductID AS (sod.SalesOrderID, sod.ProductID), pb_SalesOrderID AS (sod.SalesOrderID) | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by Steve Jones - SSC Editor) |
Minimal Stats Creation If I want to create statistics in a SQL Server 2022 database, what do I need to include in the CREATE STATISTICS command? Answer: The name for the statistics, the table on which to create them, and the column(s) on which to create them Explanation: The minimal items in the CREATE STATISTICS statement are: statistics name table column(s)The CREATE STATISTICS will not generate a name. Auto-created statistics will get auto names. Full scan or sample are not needed and the statement will sample at a rate that is determines. Ref: CREATE STATISTICS - https://learn.microsoft.com/en-us/sql/t-sql/statements/create-statistics-transact-sql?view=sql-server-ver16 |
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 |
UPDATE query is running slow and is causing blocking - Hi All, We have an UPDATE query which is causing a lot of blocking in QA env. Its taking more than 4 hours and keep running and we see a waittype as "(151ms)PAGEIOLATCH_SH:QA4_ORS:3(*)". Worst part is, the app team has scheduled this stmt at multiple times of the day. Even before the 1st UPDATE completes, […] |
SQL Server 2016 - Administration |
SQLPS (and SQL Agent PowerShell steps) don't work after Windows upgrade to 2019 - We were running SQL2016 on Windows 2012R2 without issues. We've just had an OS upgrade to Windows 2019 and now we can't run SQLPS.exe or any SQL Agent PowerShell steps. SQLPS.exe returns: import-module : File E:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\SQLPS\Sqlps.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see […] |
How to solve "The operating system returned error 21" - Starting point was a power break with open files etc. in windows. I really do not know where to start. TITLE: Microsoft SQL Server Management Studio ------------------------------ Backup failed for Server 'DESKTOP-MB6NMGV\EDVARD'. (Microsoft.SqlServer.SmoExtended) For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=16.100.47021.0&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Backup+Server&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ The operating […] |
SQL Server 2016 - Development and T-SQL |
The DATETIME data type question - I know that the DATETIME data type is no longer an ANSI/ISO Standard and I have heard the Microsoft plans to eventually stop supporting it but I cannot find any mention of this out on the internet, besides the few comments I came across which I cannot find now. So does anyone know if Microsoft […] |
SQL Server 2012 - T-SQL |
AttachDbFileName in Connection String in Vb.Net code gives errors. - While using AttachDbFileName in the connection string to attach database to localdb,The following error occurs Error: The logical database file 'Common WM_log' cannot be found. Specify the full path for the file. Could not open new database 'C:\USERS\SOURCE\REPOS\WINDOWSAPP20\WINDOWSAPP20\BIN\DEBUG\COMMON.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file C:\Users\source\repos\WindowsApp20\WindowsApp20\bin\Debug\common.mdf failed. A database […] |
SQL Server 2019 - Administration |
Concerns about database access after migrating to new server - CNAME record - Hi all, I'm planning to migrate a database from SQL Server 2008 (Windows Server 2008 R2) to SQL Server 2019 (Windows Server 2019), I've ran the Data Migration Assistant to assess the move and it came back without any issues, I'm also planning on using this tool for the actual migration. There are currently multiple […] |
Recovery Point Objective (RPO) - Does the following backup strategy satisfy the RPO of 24 hours. these are SIMPLE recovery. no transaction FULL every sunday at 12 am. DIFF daily at 2am |
SPID 0 is blocking some SPID. - This is the 1st time I have seen some sessions blocked by SPID 0. Does anyone know what this zero session is? |
SQL Server 2019 - Development |
How to copy from one to another almost identical db - I have inherited a demo db called demo_1 and a live db with +300 tables. They are almost identical, but there has been done some work on the live db, which has not been done on the demo. Its missing primary fields, some keys, a few identity fields. Its pretty easy to copy the […] |
Split json column - I have a column which has the following data in it for example {"changedAttributes":[{"logicalName":"line1","oldValue":"street1","newValue":"street2"},{"logicalName":"city","oldValue":"City1","newValue":"City2"},{"logicalName":"phone","oldValue":"123","newValue":"345"}]} There maybe 100 logicaname values not just the three here How do I write in sql a query to extract the logicalname, old value and new value for each logical name that exists in the column Lets presume the table is […] |
Integration Services |
How to add a variable to Data Flow task? - We have a Data Flow task to load a table from one server to another. But the destination has one extra column which I have to pass from a package variable. How I can add it? In a Mapping tab it has an drop-down option against this column, but how I can insert my […] |
SQLServerCentral.com Website Issues |
HTML on the published article is broken - Hey team, I need help with fixing the HTML on my published article. SQL Window Functions Series: RANK() and DENSE_RANK() It is all broken and is providing no value to the reader. Please fix it ASAP |
SQL Server 2022 - Administration |
Table with high unused space - I have a table where over 50% has unused space How can I reclaim this space back? Index maintenance? |
SQL Server 2022 - Development |
Cannot able to login to mysql as localhost - I have a query in mysql I have created a account with test@localhost and i want to access the particular database where I have given access to the db like all necessary permissions and all these my sql accounts are hosted in a server and now when i try to login in local mysql workbench […] |
Update CSV string with lookup table - I need to replace word(s) in CSV string in table tblA, in the [original] column, by [word] from lookup table tblB. The new CSV string will be stored in tblA table, in the column [modified]. If the [tblB].[synonyms] column doesn't contain the word from CSV in tblA, then the original word will be kept. For […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Laden...
Laden...
© 2024