Here is my table: Table Purchase Report PURC_ID CUS_ID Product QTY Date 1 John Leg_01 2 2021-04-09 2 John Head_01 1 2021-04-09 3 Dawn Head_01 1 2021-04-09 4 Dawn Shoulder_01 2 2021-04-09 5 Dawn Leg_01 1 2021-04-09 6 Keith Leg_01 2 2021-04-09 I would like to build the report as follow: Table 4: (PURC table wil…
Tag: sql-server
How do I construct my WHERE clause to pull records based on this specific criteria?
I am using SQL Server 2014 and I have a T-SQL query running against a specific Table (t1). Table t1 includes 3 columns named [HR_LeftDate], [Payroll_LeftDate] and [Status]. In that table, there are records which have their [HR_LeftDate] and [Payroll_LeftDate] as ‘NULL’ and some other records which…
How to select Maximum and minimum date values and pass those as a query
I have a table with the following entries CustomeID TransDate WorkID 1 2012-12-01 12 1 2012-12-03 45 1 2013-01-21 3 2 2012-12-23 11 3 2013-01-04 13 3 2013-12-24 16 4 2014-01-02 2 I am trying get the data between two dates and the required date values are minimum and maximum values of the column. I am able to …
How to replace identical values with incremental integers?
I have this SQL select: The output will look something like this: How can I replace the identical values of UserId with incremental integers, so that the output will look something like this: I have tried grouping the identical UserId rows first then joining it with the same table while having an incremental …
Query which outputs the number of athletes that voted for someone in the same athletePosition? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question Like the title says, SQL query which outputs the number of athletes that voted for someone in …
Display duplicate row indicator and get only one row when duplicate
I built the schema at http://sqlfiddle.com/#!18/7e9e3 I would like to write a query that would produce the following result characteristics : Returns only one owner per boat When multiple owners on a single boat, return the youngest owner. Display a column to indicate if a boat has multiple owners. So the fol…
Create Continuous Enrollment islands for a certain sub-population
My end goal is to create islands of continuous enrollment days for each CLIENTID for a single sub-population: ‘Adult Expansion’ for calendar years 2019 and 2020. A CLIENTID can be associated with …
How to show a table with custom message in SQL?
Is it possible to show a message before a table in MS SQL Server? Assuming this have a table of NAMES with columns firstName and lastName This code/query shows only the tables firstName and lastName without the message ‘This is a list of names’ Answer Run the query from SSMS with the Results to Te…
MSSQL COALESCE function with multiple non null values
I am trying to get data (T_Stamp, Destination, Weight, Line) from two tables using variable time intervals and a destination selection. This is going into an Ignition SCADA. My SQL code below works for most cases except when there are entries into both tables with the same timestamp. In those cases it shows o…
Pivoting a dynamic column based on split value
I Have a couple of tables as per below Position table Id PositionName 1 Developer 2 Analyst 3 Tester Employee table Id Name Positions 1 John 1,2 2 Lisa 3 3 Smith 1 4 Willow NULL 5 Burly 2,3 …