|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Rounding and Sums | |
I've got this code:
WITH numberCTE (n) AS (SELECT n FROM (VALUES (3.7), (-2.1), (2.9), (-3.1) ) A(n) ) SELECT ROUND(SUM(n),0), SUM(ROUND(n,0)) FROM numberCTEDo you expect these two values in the result set to be the same? | |
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) |
Counting Some Rows I have two tables that are related. In my OrderHeader table, I have this data: I have this data in the OrderLine table: These two tables are linked with the OrderKey in my Power BI Model. I want to add a column to the OrderHeader table that will keep the total number of rows from OrderLine that match the OrderKey for that row. What function should I use for my new column? Answer: COUNTROWS(RELATEDTABLE(OrderLine)) Explanation: The RELATEDTABLE() function will filter the rows for related tables. This will result in this data: Ref: |
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 |
Restoring a database backup from SQL 2000 to SQL 2017 (via SQL 2008) - not good? - We are upgrading our old SQL 2000 box to SQL 2017. I know you cannot restore a backup from 2000 directly to 2017, so we are first restoring it to a SQL 2008 box, backing it up from there and then restoring that to SQL 2017. When we restore that to SQL 2017 will that […] |
Performance regression after upgrade to 2017 - Hi, We recently upgraded our production DB server from 2008R2 standard edition to 2017 Enterprise edition. we have noticed queries that would run for couple sends are taking long time to run and causing timeouts in applications. I have rebuild indexes and updated the statics. I checked the sql server logs to see if there […] |
SQL Server 2017 - Development |
Convert Date field to YYYYMMDD from YYYY-MM-DD in SSIS - Hi, I've got a table containing Dates in YYYY-MM-DD which I need to change to YYYYMMDD in SSIS. I've made some progress after watching this video from Steve Fox. I'm using SSIS & this all works OK until I want to create a Derived Column on a Date field. In the video, some expressions are […] |
Remove or Replace unwanted Characters from a table - Hi, I have some Tables that I want to transform in SSIS. Any occurences of more than one comma or other Character (|,/ etc..) should be removed leaving just one. This needs to be applied to the whole Table. Can anyone advise the best way to do this in SSIS? Thanks |
SQL Server 2016 - Development and T-SQL |
stored procedure insert into a table -parameter containing the name of the table - Hi, I have 10 tables each with 2 columns (Id- identity, Name_xxxx) The name of the second column is different from a table to other. I want to write a stored procedure to insert a record into the table, but with 2 parameters in input (the name of the table and the value) exec sp_InsertIntoTable […] |
Administration - SQL Server 2014 |
Problem with a heap table - I inserted in a heap table millions of rows. When finished, i executed select t2.name,t1.name,t3.name,t3.rows from sys.sysobjects as t1 inner join sys.schemas as t2 on t2.schema_id=t1.uid inner join sys.sysindexes as t3 on t3.id=t1.id where t1.xtype='U' and t3.status & 64 = 0 and t3.status & 16777216 = 0 and t3.status & 8388608 = 0 and t2.name='dbo' […] |
Duplicate statistics - execution plan disruption - Hello, I will need your insight on the content of the execution plans in relation to the statistics. Request 1: do the values ??in the section only contain the statistics actually retained for the plan in question or is it the list of all potentially useful statistics? Request 2: for a particular step, how […] |
SQL 2012 - General |
Timeoffset calculation logic - Please help me with the timeoffset logic calculation. I get time offset and start time of a server as input. My requirement is to show the result to the user after 1 hr and 30 mins of start time. I'm unable to do the timeoffset logic calculation based on this data. My DB runs at […] |
SQL Server 2012 - T-SQL |
Arithmetic Overflow Error - I am getting an Arithmetic Overflow error on this field, suggestions on a fix? CAST(ROUND(CAST(COALESCE(r.ActualAllowed * 100.0 / NULLIF(r.Allowed, 0), 0) AS FLOAT), 1) AS VARCHAR(10)) + '%' AS FeeSchedulePercentDiff |
SQL Server 2019 - Administration |
SSAS - Query time when processing - works with 2017 - timesout with 2019 - Hi, I'm wondering if someone can help us out here as we are at a loss. We have at present a process which works like this; 1. Server A (SQL 2016) kicks off an SSIS package which is locally stored as a .dstx file 2. That package connects to Server B (SQL 2017) which has […] |
connecting to named instances from sql server to sql server, firewalls - I am setting up a Win2019/Sql2019 server. Setting up the firewalls for the default services are fairly straight forward using the article: https://docs.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access?redirectedfrom=MSDN&view=sql-server-ver15 All the information is for inbound connections. I'm trying to connect to a named instance through the firewall which is an outbound connection. I can add a specific firewall rule for each […] |
SQL Server 2019 - Development |
Query JSON data - I have a field in my DB that has a string of JSON data. This is an example: [{"id":"36653","invoicenumber":"8224131","billinginvoiceid":"948439"},{"id":"36651","invoicenumber":"8224133","billinginvoiceid":"948437"},{"id":"36652","invoicenumber":"8224134","billinginvoiceid":"948438"},{"id":"36654","invoicenumber":"8224155","billinginvoiceid":"948440"},{"id":"36655","invoicenumber":"8224161","billinginvoiceid":"948442"}] As you can see, there are basically 3 fields: ID, invoicenumber, and billinginvoiceid. This string can have 1 record or 1000 records, there really isn't a limit. I need to be able to query that field […] |
Invalid column name error - I am trying to delete duplicate rows, but I get an error message saying that 'RowNumber' is an invalid column even though I have that column (as an alias). I tried running the SELECT and DELETE statement together and it still didn't work. I know it doesn't exist in the base table because it is […] |
SSRS 2016 |
how to get fixed length file out of SSRS - In rsreportserver.config file, how can I set CSV export to have a field delimiter of none So that I can extract a fixed length file? I tried keeping it empty but it gives commas after each field value. Also if possible, please provide the script to get fixed length file and some of the fields […] |
COVID-19 Pandemic |
Daily Coping 15 May 2020 - Today’s tip is to show your gratitude to people who are helping to make things better. My thoughts: http://voiceofthedba.com/2020/05/15/daily-coping-15-may-2020/ |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |