|
|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Using Outer Joins | |
I have this data in a SQL Server 2019 database:
Customer table CustomerID CustomerName 1 Steve 2 Andy 3 Brian 4 Allen 5 Devin 6 Sally OrderHeader table OrderID CustomerID OrderDate 1 1 2024-02-01 2 1 2024-03-01 3 3 2024-04-01 4 4 2024-05-01 6 4 2024-05-01 7 3 2024-06-07 8 2 2024-04-07I want a list of all customers and their order counts for a period of time, including zero orders. If I run this query, how many rows are returned? SELECT c.CustomerName, COUNT(oh.OrderID) FROM dbo.Customer AS c LEFT JOIN dbo.OrderHeader AS oh ON oh.CustomerID = c.CustomerID WHERE oh.Orderdate > '2024/04/01' GROUP BY c.CustomerName | |
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) |
Cloud Sources for the Data Migration Assistant Which cloud sources can be used for the current Data Migration Assistant (Sep 2024) Answer: Amazon RDS only Explanation: Only Amazon RDS is supported as a source. Ref: Supported Source and Target Version - https://learn.microsoft.com/en-us/sql/dma/dma-overview?view=sql-server-ver16#supported-source-and-target-versions |
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 2016 - Administration |
Data cleansing/conversion tool HPE - Hello. I am looking for a tool Data cleansing/conversion, was recommended HPE any recommendation about this tool or any others ? Thank you |
SQL Server 2016 - Development and T-SQL |
How to merge two tables with unlike fields - How to merge two tables with unlike fields. I have two table with one unlike field that I need to show on one row. The query I have this far is this. /* Asset value per line */ Select ast.siteid, ast.location, ast.linenum, SUM(ast.purchaseprice) as [purchaseprice], ast.replacecost from asset as ast with (NOLOCK) where ast.siteid like […] |
strange selection for update - Hi, yesterday I had to update several rows of a table. The rows for update where selected by a select-statement for testing the results; the selection for the update-statement selected this sub-selection but I missed that I renamed the primary key within the selection; normaly I would think that SQL should raise an error (because […] |
Review what columns are used - I have a couple of databases One would be regarded as the source and another as the destination The destination is kind of a subset of source having gone through an ETL process Although the E part is scripted access as both databases reside on the same server So, there are a number […] |
Merge rows in SQL - I have a table like below ID Ident source val opendate closedate IsActive -------------------------------------------------------- 101 euid01 File01 x010 01-01-2023 01-01-2999 1 101 euid02 File01 x111 01-01-2023 01-01-2999 1 101 euid02 File01 x222 01-01-2023 01-10-2024 0 102 euid01 File11 x010 01-01-2023 01-01-2999 1 102 euid02 File12 x333 01-01-2023 01-01-2999 1 102 euid02 File10 x444 01-01-2023 01-10-2024 […] |
Development - SQL Server 2014 |
How can I tell if an UPDATE command updated any rows? - I am calling an Update routine from C# and need to determine if the Update routine found a matching row to update. If it does not, I call the Insert Routine. I was hoping that if no row was updated, I would get an error which would tell me that I need to do the […] |
SQL 2012 - General |
How to determine if a DB is currently being used - Hi - I'm looking for advice regarding the best & quickest way to establish whether or not a SQL2012 DB is being used. Many thanks Dax |
SQL Server 2019 - Administration |
Query is timing out - I have a view on ServerA that fetches some data from ServerB and ServerC. The linked servers are configured properly. The query itself runs fine on ServerB and ServerC. But when I run it from ServerA, I get 'Query timeout error', yet some days, it runs fine. Some days it executes in a minute but […] |
SQL Server 2019 - Development |
How to pass a variable in look up transformation in SSIS ? With Oracle database - We have a need to pass a variable in the look up query against Oracle database using SSIS, is there a way to pass a Sql query output (variable) in SSIS ? |
problem with PIVOT Table - Thanks in Advance! I'm having trouble grouping all counts and sums on one line for each county which should not look like (Code attached) Note one county is repeated and most are like that: County MH SA DD Cost Camden 0 0 1 152.88 Pitt […] |
Integration Services |
Visual Studio 22 / SSIS Project / (Project) Connection problem - Hello, First of all, I find it odd/annoying that I can't exclude a Project level connect from a package Connection Managers... at least I can not do it. Why should they show / fill the space in packages with nothing to do with those connections. But even more annoying is that when you have a […] |
SQL Server 2022 - Administration |
System views in a contained availability group - I have a query that runs in a job to check on orphaned users. On a server with a contained availability group it gives false positives. I pinned it down to the following different result of the same query. When I am in SSMS and connected to one of the servers in the AG. I […] |
SSISDB Folder creation Error - We recently installed SSIS on SQL Server 2022 machine. Trying to create a folder under SSISDB integration Services catalog is giving this below error. Operation 'Create' on object 'CatalogFolder[@Name='Testing1']' failed during execution. (Microsoft.SqlServer.Management.Sdk.Sfc) Cannot find either column "internal" or the user-defined function or aggregate "internal.is_valid_name", or the name is ambiguous. Cannot find the folder 'Testing1' […] |
SQL Server 2022 - Development |
Find rows with very close time stamps - Given the following table and query, this will return any records(based on message_id) that have timestamps within 2 seconds. This works and gives me the correct output. So 2 questions. how does this solution stack up compared to other solutions, if the total possible clicks for a particular messageid is very large, is this still […] |
Update Function - Hello everyone, I need your help. I have a “datetime” column (data type is Varchar(64) )with the following content: Sun Sep 29 2024 09:28:55 GMT+0000 (Coordinated Universal Time) I would like to update the column so that I only get the time in the format HH:MM:SS. I have tried many solutions, but none of them […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |