Laden...
|
|
|
|
|
|
Question of the Day |
Today's question (by Sergiy): | |
How Many Distinct Records | |
You have a table containing non-unique records: CREATE TABLE #QOD ( Number int NOT NULL, String varchar(50) NOT NULL ) INSERT INTO #QOD (Number, String) SELECT 10, 'abcdefg' union all select 20, 'abcdefg' union all select 20, 'abcdefg' How many records are returned by each of the following queries? --Query1 select distinct NEWID(), Number, String FROM #QOD; --Query2 select NEWID(), Number, String FROM #QOD GROUP BY Number, String; | |
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) |
How Many Rows Remain? I have written this code. DECLARE @founders TABLE (foundername VARCHAR(50)); BEGIN TRAN; INSERT @founders VALUES ('Andy'); INSERT @founders VALUES ('Brian'); INSERT @founders VALUES ('Steve'); ROLLBACK; SELECT * FROM @founders AS f;How many rows are returned from the SELECT? Answer: 3 Explanation: There are 3 rows returned. Table variables are not part of the transaction space. This is one good technique for use with logging applications, as you can capture information about a transaction and access it in a CATCH or outside of a rollback. I haven't written a question like this in a long time, but was amused seeing it from Brent Ozar on Twitter and the range of responses. Ref: Half Of You Don’t Understand Variables and Transactions - https://www.brentozar.com/archive/2020/08/half-of-you-dont-understand-variables-and-transactions/ table - https://docs.microsoft.com/en-us/sql/t-sql/data-types/table-transact-sql?view=sql-server-ver15 Variables - https://docs.microsoft.com/en-us/sql/t-sql/language-elements/variables-transact-sql?view=sql-server-ver15 (PR submitted if the explanation does not appear on the page. |
Featured Script |
Searching for orphaned DB files on the SQL server [email protected] from SQLServerCentral See how to find those files that are not in use, but are taking up space on your instance.
|
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 |
DEA - What is the use of DEA tool in sql ? how can we install on sql ? |
SQL 2017 MLS - cant add new python packages - Hi I'm new-ish to MLS and have been trying to add new python packages like attrs to the python but it hasn't been working. Our set up is SQL 2017 with CU14 on Win 2016. Python version is 3.5.2 The usual command I run is : "pip install attrs" ( without quotes ) and I […] |
Index Fragmentation - I am looking into fragmentation in one of my databases and ran across these stats - should I be rebuilding these indexes? That's what it looks like, just want some ideas/confirmation to see if I'm on the right track. |
SQL Server 2016 - Administration |
SQL Server 2016 seeding automatic stuck - Hi all, Problem help please, I have 2 servers in sql server 2016 and i have started seeding databases to the DR server within the GUI of AOG which is FCI problem is that one of my dbs which is 2 TB with take 1 month to finish. I need to stop this and continue […] |
will this get replicated to secondary replica - Dear Experts, In Availability Group, if we move ndf file to another drive on primary, will this get replicated to secondary replica |
SQL Server 2016 - Development and T-SQL |
SQL Query - FULL JOIN multiple tables but return NULL results - Good day! Need help with my sql query code; first FULL JOIN "ILEtransfer" no NULL result but im getting NULL result once i add a FULL JOIN "ILEmsales" Thank you in advance! here's my sql query code; ;WITH Barcodes AS ( SELECT [BBI$Barcodes].[Item No_] ,[BBI$Barcodes].[Description] ,[BBI$Barcodes].[Variant Code] FROM [BBI$Barcodes] ), ILEtransfer AS ( SELECT [BBI$Item […] |
Administration - SQL Server 2014 |
Server local connection provider has stopped listening - Hello, Once / twice a week I'm getting the following error. Server local connection provider has stopped listening on [ \\.\pipe\SQLLocal\MSSQLSERVER ] due to a failure. Error: 0xe8, state: 4. The server will automatically attempt to re-establish listening. where should I search for the source of the error? Is this error is due to the […] |
Development - SQL Server 2014 |
Number weeks from April to September for every year - I want to number weeks from April to September for every year, such that week 1 starts 1st of April and ends the following Saturday and week 2 starts first Sunday of April and ends the following Saturday and so on.... till the end of September. How do I do that using TSQL. Thanks in […] |
SQL Server 2012 - T-SQL |
slow query performance - Hi All, I have a SELECT query which is taking more 8 mins. Can you please help me in making the query run faster (if possible) . There is no blocking . Seeing PAGEIOLATCH_SH waittype for most time. The table is a clustered index table. There is no non-clustered idx on mule_batch_id column. Query: use […] |
SQL Server 2019 - Administration |
\'REMOTE ACCESS\' setting flipped back to 0 overnight ?? - Any reason why our SQL Server 2016 Standard edition instance would have flipped the 'REMOTE ACCESS' setting back off? Here's what happened: - I ran the following code AS IS on both SQL Servers: sp_configure 'show advanced options', 1; GO RECONFIGURE; GO EXEC sp_configure 'remote access'; -- Display current setting GO --EXEC SP_CONFIGURE 'remote access', […] |
SQL Server 2019 - Development |
SSIS 2019 - Conditional Expression for the value of a variable- fails evaluation - Hi All, Ran into an error trying to evaluate the following expression for a variable value: @[User::varBadRows] > 0 ? (DT_STR, 50, 1252) ("There are " + (DT_STR, 3, 1252) @[User::varBadRows] + " rows with a non-matching SPID value.") : NULL(DT_STR, 50, 1252) I'm using Visual Studio 2019 Pro and my target environment is SQL […] |
The backup set holds a backup of a database other than the existing 'MyDB' - I'm trying to restore a database from our production server to my local machine using the following script but still get the error, 'The backup set holds a backup of a database other than the existing 'MyDB' database. USE [master] RESTORE DATABASE [MyDB] FROM DISK = 'C:\MyDB.bak' WITH REPLACE, MOVE 'MyDB' TO 'C:\MyDB.mdf', MOVE 'MyDB_log.ldf' […] |
Find row closest to date - Just having trouble getting this to work as I hoped. Trying to extract entire row from one table with a date closest and before another date in the 1st table. Sample table and 1st try below. Any help is appreciated Trying to get: 1, 2020-08-05, 2020-08-03, 25 2, 2020-08-04, 2020-08-03, 34 3, 2020-07-28, […] |
SQL Select with condition - Hi, In my sql table, there is a column which have string of text : Column 2ABF CD06-000000001234506-0000000001156 306-000000000345206-0000000000356 I would like if the 1st character is 2 then out put as ID Code Num1 Num2 Num3 Num4 2ABF CD 123.45 11.56 if the 1st character is 3 then ID Code Num1 Num2 Num3 Num4 […] |
Integration Services |
SSIS package with Multiple Streams - I have a package with has multiple streams and calls the same SP. Why do streams are used in SSIS, like to multitask with the same SP? I do have a performance issue with this package. Will reducing the streams help? ( like less SP calls) |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. [email protected] |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Laden...
Laden...