Laden...
|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
The Rank Window II | |
I have this table and data: CREATE TABLE [dbo].[SalesTracking] ( [SalesDate] [datetime] NULL, [SalesPersonID] [int] NULL, [CustomerID] [int] NOT NULL, [PONumber] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [paid] [bit] NULL ) ON [PRIMARY] GO CREATE CLUSTERED INDEX [SalesTrackingCDX] ON [dbo].[SalesTracking] ([SalesDate]) ON [PRIMARY] GO INSERT dbo.SalesTracking (SalesDate, SalesPersonID, CustomerID, PONumber, paid, total) VALUES ('2024-03-15 10:45:55.067', 1, 1,'PO965' ,1, 100), ('2023-09-24 10:45:55.067', 1, 2,'PO627' ,1, 200), ('2022-07-02 10:45:55.067', 1, 3,'PO6' ,1, 300), ('2022-11-03 10:45:55.067', 1, 4,'PO283' ,1, 400), ('2022-11-26 10:45:55.067', 1, 5,'PO735' ,1, 500), ('2023-04-28 10:45:55.067', 1, 6,'PO407' ,1, 600), ('2022-09-09 10:45:55.067', 1, 7,'PO484' ,1, 700), ('2024-03-13 10:45:55.067', 1, 8,'PO344' ,1, 700), ('2024-04-24 10:45:55.067', 1, 9,'PO254' ,1, 800), ('2022-06-19 10:45:55.067', 1, 10,'PO344',1, 800) GO When I run this query, how many unique values are returned for the SaleRank column? SELECT st.SalesDate , st.SalesPersonID , st.total , DENSE_RANK () OVER (PARTITION BY st.SalesPersonID ORDER BY st.total desc) AS SaleRank FROM dbo.SalesTracking AS st; | |
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) |
Partial Backups I What is a partial backup for a read-only database? Answer: a backup of the primary in a read only database Explanation: A partial backup of a read-only database contains only the primary filegroup. Ref: Partial backups - https://learn.microsoft.com/en-us/sql/relational-databases/backup-restore/partial-backups-sql-server?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 - Development |
Fuzzy logic between two columns - Hello, I have tried various methods to accomplish this using functions like PATINDEX, DIFFERENCE, and the Levenshtein Distance function, but I haven't been successful. I have two columns of type VARCHAR, and I need to determine if a specific word exists in both columns. For example, in the rows below, the string "603260" matches. The input do […] |
SQL Server 2019 - Administration |
Sync SQL Server and Kafka in real time - Hello, Let say, my .NET API has been inserted successfully into SQL Server Database. It is possible, this data also inserted in Kafka in real time ? This transaction should be done in .NET API or should be done in SQL Server by configuration ? Please help me to understand more and better |
T-SQL - Restore Database - Hey, I've previously used this or something like this: RESTORE DATABASE [DBNAME] FROM DISK = N'X:\Path\To\File\.bak' WITH FILE = 1 ,MOVE N'DBNAME' TO N'U:\Path\To\File\DBNAME.mdf' ,MOVE N'DBNAME_log' TO N'L:\Path\To\File\DBNAME_log.ldf' ,NOUNLOAD ,STATS = 5 But I've now encountered a DB with 27 data files (+1 log file). Is there a way to relocate the files on the […] |
SQL Server 2019 - Development |
Is anybody using Windows 2022 clustered SQL Failover cluster ( 2019 CU30 ) - How do you configure the cluster resources to be able to use Distributed Transactions ? Documentation ( 01/15/2014 ) is unclear and doesn't show a working solution. Begin Distributed Transaction fails ! Msg 8501, Level 16, State 3, Line 12 MSDTC on server 'VirtSQLServer\MyInstanceName' is unavailable. |
Query Help to show record in single row - Hi All, need help with an SQL query. We have an existing table that's already formatted this way, and I am having trouble extracting the data in single record. Current Output: EXPECTED OUTPUT: The EndDate and EndTime I want it displayed in the same row where BName like '% Start' I tried to do this through […] |
MSDTC not available on Windows 2022 clustered SQL 2019 CU30 - I connect to this clustered instance and run : begin distributed transaction Msg 8501, Level 16, State 3, Line 2 MSDTC on server 'ClusteredTargetServer\Instance' is unavailable. I have configured the clustered msdtc of this instance: Test-Dtc -LocalComputerName $env:COMPUTERNAME -Verbose VERBOSE: ": Firewall rule for "RPC Endpoint Mapper" is enabled." VERBOSE: ": Firewall rule for […] |
General |
What Version MS SQL Server and SSMS Am I Running? and Git with MSSSQL - Information I've run across searching other topics led me to want to find out what version I'm running. This was motivated by trying to learn if git/github would be good tools for version control on my database which led to the question of version. I found an article that told me to run SELECT @@version. […] |
Several Questions: Relationships and SSMS and Data Diagrams - I'm struggling setting relationships among tables. I understand the one-to-many, many-to-one, many-to-many, and self-referential concepts. It's implementing them that I find a bit vexing. I've used queries like this successfully: ALTER TABLE clan.parents ADD CONSTRAINT FK_FatherID_PeopleID FOREIGN KEY (parentsFatherId) REFERENCES clan.people (peopleID); How can I view relationships after I've completed queries like the above? After […] |
Time Outs Here - Several times in the last couple of days I've had submissions time out with a 504 error returned. After multiple submissions, I've eventually got my posts through. I've learned to type the posts in a notepad from which they can be copied instead of having to retype them. |
Data Diagrams: Data Types with Column Names - In the ss below I highlighted several rows in each block showing tables in diagram view to show where I think data type assignments could be displayed. Is there a reason that SSMS doesn't display data types assigned to column names? I've searched to see if there is a way to add them but came […] |
Data Diagrams: Data Types with Column Names - In the ss below I highlighted several rows in each block showing tables in diagram view to show where I think data type assignments could be displayed. Is there a reason that SSMS doesn't display data types assigned to column names? I've searched to see if there is a way to add them but came […] |
Data Diagrams: Data Types with Column Names - While this might not be an issue for those more knowledgeable and experienced than I am, I've come to wonder why the blocks that represent tables and contain the names of columns in those tables don't also include assigned data types in parentheses or brackets following column labels. I highlighted the first 4 columns in […] |
SQL Server 2022 - Administration |
Have 3 SQL Server Database in different 3 Windows Server Machine - Hello, I am newbies in SQL Server Administration My planning is to setup - 3 SQL Server Database in Server A, Server B & Server C. All these 3 SQL Server Database have identical schema and the data should be identical. Other word, SQL Server Services without shared storage. All the database files are on […] |
SQL Server 2022 - Development |
Convert stored procedure into a Table-valued function - <sorry, duplicate> =( |
Convert stored procedure into a Table-valued function - Feel like I'm missing something blatantly obvious. I am trying to return the cost of each of a set of ingredients as of a specific date (so I can sum them in the next step, for example). It works fine if I create it as a stored procedure, but when I try to create a […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. [email protected] |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Laden...
Laden...