|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Subqueries II | |
What is wrong (if anything) with this code?
SELECT * FROM Sales.SalesOrderHeader AS soh WHERE customerid IN (SELECT soh.CustomerID FROM Sales.Customer AS c WHERE soh.CurrencyRateID = 1 ORDER BY c.ModifiedDate) | |
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) |
More Funny SELECTs What does this code return? SELECT ( SELECT COUNT (*), MAX(soh.OrderDate) AS latestorder FROM Sales.SalesOrderHeader AS soh WHERE soh.OrderDate > '01/01/2011' AND soh.OrderDate < '01/01/2012') AS OrdersIn2000 , ( SELECT COUNT (*), MAX(soh.OrderDate) AS latestorder FROM Sales.SalesOrderHeader AS soh WHERE soh.OrderDate > '01/01/2012' AND soh.OrderDate < '01/01/2013') AS OrdersIn2001 , ( SELECT COUNT (*), MAX(soh.OrderDate) AS latestorder FROM Sales.SalesOrderHeader AS soh WHERE soh.OrderDate > '01/01/2013' AND soh.OrderDate < '01/01/2014') AS OrdersIn2002; GO Answer: An error Explanation: This returns an error. The error is: Msg 116, Level 16, State 1, Line 6 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. This is actually returned 3 times, one for each subquery. A subquery cannot return multiple results unless this is used with an EXISTS or IN. Ref: Subqueries - https://learn.microsoft.com/en-us/sql/relational-databases/performance/subqueries?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 2016 - Administration |
Active and Active Cluster - Hi Team, I am planning to apply security updates for SQL Server 2016 on Active/Active Cluster servers. Could you please advise on the proper procedures to follow? Specifically, which server should I apply the updates to first, and when should I reboot the servers? Your guidance would be greatly appreciated. Thanks |
Tracing a performance issue - Edit: This is a duplicate of another post. |
Tracing a performance issue - Hello, We have a SQL agent job that runs daily. It runs a procedure, which for the purposes of this post, I will refer to as 'Procedure A'. That procedure runs other procedures. Every few months we get an issue where it appears to have stalled. Task manager is showing the SQL Server process at […] |
SQL Server 2016 - Development and T-SQL |
identify consecutive records greater than 1 - Hello I need help identifying all records that have consecutive hours (time in order) of greater than 1 for the value field. The output I am looking for would have Number,Start Time,End Time, Average of val over that time range that is identified. create table LunchTable ( Number integer, Value decimal(15,2), StartTime datetime ); insert […] |
Import data from json file with special characters - I am using the following script to import data from a json file. This file contains special characters for some names. Once imported, I noticed that sql server is replacing the special characters with some other ones. Is there away to import special characters without changing them? Any help is greatly appreciated. CREATE TABLE test3 […] |
Administration - SQL Server 2014 |
SSIS package works in VS but failed in SSMS - Please help and thanks. Package:Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.". |
SQL Server 2019 - Administration |
SQL Server migration using replication - I've set up replication in my SQL 2019 environment in attempt to migrate SQL databases individually from one datacenter to another. in my testing of one database several issues were found and any advice would be appreciated. 1. There several missing indexes 2. very large tables cannot be filtered on for transaction replication(post snapshot migration) […] |
Automating SQL Server 2019 Setup and Configuration Across Multiple Servers - Hi everyone, I’m looking to automate the installation and configuration of SQL Server 2019 on multiple servers in our environment. So far, I’ve been using tools like PowerShell scripting using scriptrunner, attune, pdqdeploy and dbatools for some tasks, but I’m curious if anyone has a full end-to-end solution they recommend. My main goals are: Automating […] |
SQL Server 2019 - Development |
Need a list of stored procedures that execute multiple stored procedures - Hello SSC! I hope you all had a happy and safe holiday! Apologies if this post is confusing... I have a bunch of procs that call an index rebuild proc multiple times based on column name. Basically, this is all hardcoded (I did not write this :)). I tried a bunch of scripts to identify […] |
SQL Azure - Administration |
Creating LS from IaaS to Paas using MFA - Guys - I need your help on this.... I like to create an linked server from an IaaS (VM) to a PaaS managed instance but when I heve to loging to the MI using MFA I have to respond using mij GSM ( entering a code to confirm it is me ). How can I […] |
Integration Services |
Call dynamic sql storedprocedure from SSIS execute sql task - hi, I have a table called Rules Create table Rules ( Id int , Rules Statement Nvarcahr(max) ) values Id RulesStatement 1 Sp_execute_rules @job_id , @run_id,@createid So , i will be passing the parameters from my ssis package and calling the storedprocedure. this is how i am calling in execute sql task […] |
SQL Server 2022 - Administration |
Migrating database with many orphan users. - I am currently upgrading a very old database running SQL Server 2008 to SQL Server 2022 using export & import method to a new server. I have migrated the necessary objects e.g. logins, linked servers & configuration to the new server successfully. For logins, I use revlogin procedure to script out all the logins from […] |
Primary and Secondary Filegroup - Hello, I am having database primary and secondary filegroup. Few tables/indexes are partitioned on secondary filegroup for better performance. But when I check activity monitor, I always see MDF & LDF files having response times under the Data Fil I/O but there is always 0 response time for NDF. Is this normal behaviour of MSSQL? […] |
SQL Server 2022 - Development |
Cannot install development version. - A while into install I get a Microsoft OLE DB Driver for SQL Server. The feature you are trying to use is on a network resource that is unavailable. It is looking for msoledbsql.msi. I have one locally but than I get a message: The file 'D:\msoledbsql.msi' is not a valid installation package for the […] |
sql query to check status change of an item - I have a table dbo.tblPresentationStatus (sql script attached - table script.txt) I have to select rows where the status change is wrong. (not as per the correct flow as shown in attached image status_Flow.jpg) From 'Review' the status for a specific presentation ID can change to either 'Approve' or 'Presentation' or 'Close' From 'Approve' the […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |