Skip to content
Advertisement

Tag: sql-server-2016

SQL Calculating Hourly Sales

I am trying to create a SQL report that shows hourly sales. This is from my POS system. There’s a built in table that has basically all the data I need, I’m just struggling to calculate the sum of a column if they are in the same hour. Table vRPTHourlySalesPerformance (stripped down to only show relevant info): dt_when create_hour_ordinal c_ticketitem_net_price

SQL – split numeric into 2 columns?

I am trying to split some numeric keys in my table into separate columns (to help save space in SSAS, lower cardinality) My data looks like the below.. I want to split these into 2 columns… with 4 digits in each column. (where applicable, as anything 1>9999 won’t have anything populated in the 2nd column) So an example output of

How to find ‘MAIN’ master record SQL

I’m running a query: Which returns the following results: I just so happen to know these IDs and am using them for this example. How can I return results like this across the board grouping together linked companies, until I get to the ‘MAIN’ company. There are going to be several other companies where I don’t know the IDs I

Select specific columns from the stored procedure

I have a stored procedure in other database which is maintained by other team. Assume that it is currently returning 3 columns, and my system only needs those 3 columns but the other team can add few more columns for their own use which is causing my system to fail. Other database SP And below is my query, which was

Using HAVING COUNT(column name) NOT working as expected

I have the SQL statement, working in SQL Server 2016, below where I’m getting records from an INNER SELECT UNION ALL statement and in the OUTER SELECT I’m trying to extract those records that meet the HAVING COUNT code however, my code is bringing back no records. Here are the records from my INNER SELECT statement with UNION ALL: LocationSysID

SQL Server 2016: how to get a single row view

I have been trying to word this correctly, but here’s my dbfiddle Table: Expected Output: CustomerKey processdate Product_Mix Product_Mix_Expanded 101 2021-05-01 12,3,5 CCcount, CHKCount, SACount 102 2021-02-03 1,3,1 CCcount, CHKCount, SACount 103 2019-04-12 4,0,2 CCount, SACount As you can see, I used STUFF, but not sure if that’s the right approach. I need the Product Mix showing the count and

Advertisement