|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Dirty Pages | |
What is a dirty page? | |
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) |
Decoding the Code What does this code do? SET DATEFIRST 7; WITH myTally (n) AS ( SELECT n = ROW_NUMBER () OVER (ORDER BY (SELECT NULL)) FROM ( VALUES (1) , (2) , (3) , (4) , (5) , (6) , (7) , (8) , (9) , (10)) a (n) CROSS JOIN ( VALUES (1) , (2) , (3) , (4) , (5) , (6) , (7) , (8) , (9) , (10)) b (n) CROSS JOIN ( VALUES (1) , (2)) c (n) ) , cteCurrYearDates (myDate) AS ( SELECT DATEADD (DAY, n, DATEADD (yy, DATEDIFF (yy, 0, GETDATE ()), 0)) FROM myTally) , cteMay (Mondays) AS ( SELECT cteCurrYearDates.myDate FROM cteCurrYearDates WHERE DATEPART (WEEKDAY, cteCurrYearDates.myDate) = 2 AND YEAR (cteCurrYearDates.myDate) = YEAR (GETDATE ())) SELECT TOP 1 Mondays FROM cteMay WHERE MONTH (cteMay.Mondays) = 5 ORDER BY cteMay.Mondays DESC; Answer: Finds the date of Memorial Day Explanation: This code finds the date of the last Monday of May in the current year. This is Memorial Day in the US. Happy Memorial Day! |
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 |
AG backup preference behavior - Hi All, We have 3-node AG setup in our Production environment. Primary site (2 nodes), (DR site 1node). SQL Version is :Microsoft SQL Server 2017 (RTM-CU23) Enterprise Edition:(64-bit) We have 3 user databases as part of AG. We had some performance issues and decided to offload the backup load to secondary node of AG. For […] |
Named instance connectivity - Hi We have a new named instance, I can able to connect using SSMS. However when I ping the instance name, it’s not working. It is enabled for mixed mode & enabled for the remote connections. TCP/IP port is enabled. I added the 1434 udp port in the firewall. Also changed the dynamic port to […] |
SQL Server 2017 - Development |
How to validate user if input formate no yyyy-MM-dd for created date ? - I work on sql server 2017 i need to validate user input of temp table if formate of created date not YYYY-MM-DD then reject by update status field of temp table to be Notvalid and if formate of created date is YYYY-MM-DD then update status by Valid CREATE TABLE #TempPC ( [ID] INT IDENTITY , […] |
Adding leading zeroes after the decimal - Hello, I have the following requirement to add leading zeros after the decimal from numeric string, please advice the same. Input -> OutPut 100 -> 100.0000 1.1 -> 1.0001 1.10 -> 1.0010 1.100 -> 1.0100 200.00 -> 200.0000 |
SQL Server 2016 - Administration |
SSRS Encryption Keys - We make a once per month backup of the ReportServer, ReportServerTempDB and the encryption keys from each location and store those backups at another site. My question is "Does the key change or can we use the same key that been there for a while. Please bear in mind that we periodically change the service […] |
Administration - SQL Server 2014 |
StartDate & End Date parameters - Hi, I've created a view to populate data from existing tables In my report project I built using SSDT 2014, I created Dataset to read form this view. I also set a Startdate and Endate parameter with default calander values. The expectation is for the dates to filter the dates by above parameters. The Report […] |
Development - SQL Server 2014 |
Pivot - Unpivot - Hi everybody, i have a table in SQl Server 2014 like the following: And i woul like to abtain an output like this: any help is appreciated. Thank you |
Pivot Database Names - Hello, I have been trying and failing for days to create a query, or SSRS report, that makes a column for each database on the server, with each row representing a logon. The values of the database named columns would be the database role that logon has in the database. I have been trying with […] |
SQL 2012 - General |
SQL Server 2012 Standard Media/ISO - Does anyone have a copy of SQL Server 2012 Standard handy? I just need the ISO or DVD contents to install on a new server. I have the key already from the old server, but we don't have the media any longer. I checked online and can't seem to find a good place to download […] |
SQL Server 2019 - Development |
how to select lowest value of column and corresponding date column - I am trying to get the lowest cost for a part and the highest cost for a part. along with the dates that they occurred. I almost have what I want except that in my query I don't know how to associate the lowest cost with the correct date. I understand why (because that's what […] |
Using RTRIM, LTRIM with a LEFT Function. - Is there a particular order for using the LTRIM, RTRIM with a LEFT function? Example - I only want the Left 35 from a field and want to trim any unnecessary off it. Is this the correct Syntax - LEFT(RTRIM(LTRIM(Guar.First)),35) or should I use the TRIM's then the LEFT? |
Newbie Question:If else Sql Question - In this case i am expecting the else statement to execute. please correct dECLARE @BusinessEntityId INT SET @BusinessEntityId=1003 IF @BusinessEntityId<=(SELECT MAX(BusinessEntityId) AS BusinessEntityId FROM Person.Person) BEGIN SELECT * FROM Person.Person WHERE BusinessEntityID<=@BusinessEntityId END ELSE IF @BusinessEntityId>=1000 AND @BusinessEntityId<2000 SELECT * FROM Person.Person WHERE BusinessEntityID>=@BusinessEntityId AND BusinessEntityID<=@BusinessEntityId |
SQL Azure - Development |
Troubleshooting a pipeline error - I am creating a pipeline in a data factory per this page's instructions, https://docs.microsoft.com/en-us/azure/data-factory/tutorial-incremental-copy-change-data-capture-feature-portal. I am a beginner with this and am trying to follow the instruction as closely as possible. The change, in my case, is that I am using a VM SQL installation, also in Azure, but not a managed instance. I have […] |
General |
Is SQL Express enough? - I am assisting a company in upgrading their server. It is a small business with 9 computers. The mostly have a few shared documents and spreadsheet on the server, and the server hosts and MS SQL database for their accounting software. The accounting software has a maximum of 6 users at a time. The database […] |
Integration Services |
how to pass previous week dates in stored proc parameters. - i am planning to create package with an execute sql task where it calls procedure with parameters (@fromdate, @todate) @FromDate DATETIME @ToDate DATETIME For example if i scheudle job to run this package every monday example (May9). the execute task should run for previous week dates May 2 to May8(Monday to Sunday) EXEC sp_getdetails '05-02-2022', […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |