I’m looking for a pair of SQL functions that will return the MAX and MIN value of a list of dates (or, alternatively, the MAX and MIN of two dates – I can then stack the calls to handle the whole list)…
Tag: sql-server
Data aggregation by sliding time periods
[Query and question edited and fixed thanks to comments from @Gordon Linoff and @shawnt00] I recently inherited a SQL query that calculates the number of some events in time windows of 30 days from a log database. It uses a CTE (Common Table Expression) to generate the 30 days ranges since ‘2019-01-01&#…
WHERE clause is not filtering all specifications
I’m trying to make a query with different specifications in WHERE clause and some of them are being ignored. SELECT DISTINCT f.NameLawyer AS ‘Comisiona’, f.Bill As ‘Factura’, f.Amount AS ‘…
Find the sum total of two CASE statements – (How to use a CASE expression or Lateral JOIN
I am looking to find the total profit made on an each way horse racing bet I have created a view to show odds and returns for each part of the bet, but I would like to add another column (EachWayProfit) to find the total profit. I have tried to simply SUM the two case statements though receiving a Syntax
Find the max date to last one year transaction for each group
I have to query in sql server where I have to find for each id it’s volume such that we have last 1 year date for each id with it’s volume. for example below is my data , for each id I need to query the last 1 year transaction from when we have the entry for that id as
How to convert MM/YYYY/DD format string to DATE in SQL Server?
I have a column for which I need to convert the data to DATE format. I receive below error whenever I encounter the data ‘MM/YYYY/DD’ format, but it works fine for other formats. Conversion failed when converting date and/or time from character string Sample data: SELECT ISDATE(’05/2020/29&#…
SQL Server transform xml and parse single values but not with build-in functions
I am trying to parse and transform XML values in SQL Server 2016. I can not use the the sp_xml_preparedocument or sp_xml_removedocument built-in procedures because I want to have it in a table value function. I would like to select these 4 values: testXML…821327282 Test value Test attribute Test propert…
How to join queries with a subquery?
So I’m a total newbie trying to solve this exercise where I have to find all the dishes that are marked as Vegetarian but contain Turkey meat in their ingredients. This is what I’ve tried (this is where I inner join 3 tables to find the ingredients): this is where I can’t seem to be able to …
SQL query with dynamic parameters
I tried to get some data from DB. I need get account information from my table – this type of information will depend on User. If he/she will insert account type = 1 -> he will get this information. How could I create query if it will depend on user: for example user could choose one or more account …
SQL update with more than 2 records
I’m trying to update column in this table: Expected result: And this is my update query – I get an error and I’m not sure where the issue comes from. Thank you. Error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when…